<?php

namespace api\modules\v1\controllers\patient;

use api\controllers\OnAuthController;
use api\modules\v1\forms\patient\PatientForm;
use api\modules\v1\forms\patient\MedicalForm;
use api\modules\v1\forms\patient\ClinicImgForm;
use common\models\base\PatientDiseases;
use common\models\patient\Tags;
use common\helpers\ImageHelper;
use common\helpers\CommonHelper;
use common\models\patient\User;
use common\models\patient\OperateLog;
use common\models\patient\ClinicImg;
use common\models\base\Profession;
use common\models\member\Attr;
use common\models\member\Member;
use common\models\clinic\Project;
use services\base\ProjectService;
use services\common\CommonService;
use services\common\ExcelService;
use services\dengta\robot\WechatService;
use services\patient\UserService;
use services\patient\UserUpdateService;
use Yii;
use yii\web\HttpException;

/**
 * Class SeasController
 * @package api\modules\v1\controllers\patient
 */
class IndexController extends OnAuthController
{
    /**
     * @var User
     */
    public $modelClass = User::class;

    protected $optional = ['edit-medical-noverify'];
    protected $optionalLimit = ['edit-medical-noverify'];

    /**
     * @api {get} /v1/patient/index/seas-list 公海列表【客服or医助】
     * @apiName seas-list
     * @apiGroup Index
     *
     * @apiParam {Number} type                                             类型【0客服、1医助】
     * @apiParam {String} start_time                                       开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                         结束时间【格式：2020-01-01】
     * @apiParam {String} keywords                                         关键词【姓名or手机号】
     * @apiParam {Number} source_channel_id                                来源渠道
     * @apiParam {Number} outpatient_type_id                               就诊类型
     * @apiParam {Number} clinic_id                                        门诊ID
     * @apiParam {String} patient_card_id                                  诊疗号
     * @apiParam {Number} patient_diseases_id                              病种ID【一级】
     * @apiParam {Number} sort_created_type                                到诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_revisiting_type                             复诊次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_callback_type                               回访次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_missed_type                                 未到诊天数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_updated_type                                更新时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页显示数量
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     患者列表
     * @apiSuccess {Number}  data.list.id                                  患者ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {String}  data.list.name                                患者姓名
     * @apiSuccess {Number}  data.list.age                                 患者年龄
     * @apiSuccess {Number}  data.list.gender                              患者性别
     * @apiSuccess {String}  data.list.gender_str                          患者性别值
     * @apiSuccess {String}  data.list.patient_card_id                     诊疗号
     * @apiSuccess {String}  data.list.clinic_name                         诊室名称
     * @apiSuccess {String}  data.list.created_at_str                      到诊时间
     * @apiSuccess {String}  data.list.mobile                              手机号
     * @apiSuccess {String}  data.list.wx_name                             微信号
     * @apiSuccess {Number}  data.list.outpatient_type_id                  就诊类型ID
     * @apiSuccess {String}  data.list.outpatient_name                     就诊类型值
     * @apiSuccess {Number}  data.list.revisiting_count                    复诊次数
     * @apiSuccess {Number}  data.list.callback_count                      回访次数
     * @apiSuccess {Number}  data.list.missed_count                        未到诊天数
     * @apiSuccess {String}  data.list.city_name                           地区
     * @apiSuccess {Number}  data.list.patient_diseases_id                 病种ID
     * @apiSuccess {String}  data.list.diseases_name                       病种值
     * @apiSuccess {Number}  data.list.source_channel_id                   来源ID
     * @apiSuccess {String}  data.list.source_name                         来源值
     * @apiSuccess {String}  data.list.updated_at_str                      更新时间
     * @apiSuccess {Array}   data.condition                                筛选条件
     * @apiSuccess {Array}   data.condition.source_channel_list            来源渠道列表
     * @apiSuccess {Number}  data.condition.source_channel_list.id         ID
     * @apiSuccess {String}  data.condition.source_channel_list.name       名称
     * @apiSuccess {Array}   data.condition.outpatient_type_list           就诊类型列表【同上】
     * @apiSuccess {Array}   data.condition.clinic_list                    门诊【同上】
     */
    public function actionSeasList()
    {
        $params = Yii::$app->request->get();
        $params['project_id'] = $this->projectId;

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        $type = intval($params['type'] ?? 0);

        // 查询结果
        $data = Yii::$app->services->patientUser->getSeasListPage($params, (int)$page, (int)$pageSize, $type);

        // 格式化列表数据
        $data['list'] = Yii::$app->services->patientUser->getListPageFormat($data['list'], 0);

        // 获取筛选条件
        $params = [
            'get_source_channel' => 1,
            'get_clinic' => 1,
        ];

        if ($type == 0) {
            $isCustomer = 1;
        } else {
            $isCustomer = 0;
        }
        $data['condition'] = Yii::$app->services->patientUser->getConditionList($params, $this->projectId, 0);
        $data['condition']['outpatient_type_list'] = CommonService::getOutpatientTypeList($isCustomer);
        $data['condition']['patient_diseases_list'] = CommonService::getDiseasesList();

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/patient-list 患者列表【客服列表】
     * @apiName patient-list
     * @apiGroup Index
     *
     * @apiParam {String} start_time                                       开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                         结束时间【格式：2020-01-01】
     * @apiParam {String} keywords                                         关键词【姓名or手机号】
     * @apiParam {Number} belong_member_id                                 归属人
     * @apiParam {Number} outpatient_type_id                               就诊类型
     * @apiParam {Number} effect_type_id                                   效果类型
     * @apiParam {Number} risk_type_id                                     风控类型
     * @apiParam {Number} clinic_assess_id                                 诊疗评估类型
     * @apiParam {String} body_parts_ids                                   部位IDs【多个用','分割】
     * @apiParam {String} tags_ids                                         标签IDs【多个用','分割】
     * @apiParam {Number} clinic_id                                        门诊ID
     * @apiParam {String} patient_card_id                                  诊疗号
     * @apiParam {Number} fault_diagnosis_type                             断诊次数类型【1一次、2两次、3三次、4四次以上】
     * @apiParam {Number} sort_last_revisiting_type                        上次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_revisiting_type                        下次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_last_callback_type                          上次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_callback_type                          下次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_revisiting_type                             复诊次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_callback_type                               回访次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_missed_type                                 未到诊天数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页显示数量
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     患者列表
     * @apiSuccess {Number}  data.list.id                                  患者ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {String}  data.list.name                                患者姓名
     * @apiSuccess {Number}  data.list.age                                 患者年龄
     * @apiSuccess {Number}  data.list.gender                              患者性别
     * @apiSuccess {String}  data.list.gender_str                          患者性别值
     * @apiSuccess {String}  data.list.patient_card_id                     诊疗号
     * @apiSuccess {String}  data.list.clinic_name                         诊室名称
     * @apiSuccess {String}  data.list.mobile                              手机号
     * @apiSuccess {String}  data.list.last_revisiting_time_str            上次到诊时间
     * @apiSuccess {String}  data.list.next_revisiting_time_str            下次到诊时间
     * @apiSuccess {String}  data.list.last_callback_time_str              上次回访时间
     * @apiSuccess {String}  data.list.next_callback_time_str              下次回访时间
     * @apiSuccess {Number}  data.list.outpatient_type_id                  就诊类型ID
     * @apiSuccess {String}  data.list.outpatient_name                     就诊类型值
     * @apiSuccess {Array}   data.list.patient_tags_name_arr               患者标签数组
     * @apiSuccess {Number}  data.list.revisiting_count                    复诊次数
     * @apiSuccess {Number}  data.list.callback_count                      回访次数
     * @apiSuccess {Number}  data.list.missed_count                        未到诊天数
     * @apiSuccess {String}  data.list.city_name                           地区
     * @apiSuccess {Number}  data.list.source_channel_id                   来源ID
     * @apiSuccess {String}  data.list.source_name                         来源值
     * @apiSuccess {String}  data.list.remark                              备注
     * @apiSuccess {Number}  data.list.fault_diagnosis_count               断诊次数
     * @apiSuccess {String}  data.list.diseases_name                       病种
     * @apiSuccess {Array}   data.condition                                筛选条件
     * @apiSuccess {Array}   data.condition.member_customer_list           客服归属人
     * @apiSuccess {Number}  data.condition.member_customer_list.id        ID
     * @apiSuccess {String}  data.condition.member_customer_list.name      名称
     * @apiSuccess {Array}   data.condition.outpatient_type_list           就诊类型【同上】
     * @apiSuccess {Array}   data.condition.effect_type_list               效果类型【同上】
     * @apiSuccess {Array}   data.condition.risk_type_list                 风控类型【同上】
     * @apiSuccess {Array}   data.condition.clinic_assess_list             诊疗评估类型【同上】
     * @apiSuccess {Array}   data.condition.body_parts_list                部位【同上】
     * @apiSuccess {Array}   data.condition.tags_list                      标签【同上】
     * @apiSuccess {Array}   data.condition.clinic_list                    门诊【同上】
     */
    public function actionPatientList()
    {
        $params = Yii::$app->request->get();

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientUser->getListPage($params, (int)$page, (int)$pageSize, 1);

        // 格式化列表数据
        $data['list'] = Yii::$app->services->patientUser->getListPageFormat($data['list'], 1);

        // 获取筛选条件
        $params = [
            // 'get_body_parts' => 1,
            'get_body_parts_business' => 1,
            // 'get_member' => 1,
            'get_customer_member' => 1,
            'get_effect_type' => 1,
            'get_risk_type' => 1,
            'get_clinic_assess' => 1,
            'get_clinic' => 1,
            'get_hospital' => 1,
            'get_source_channel' => 1,
        ];
        $data['condition'] = Yii::$app->services->patientUser->getConditionList($params, $this->projectId, $data['is_check_type']);
        $data['condition']['outpatient_type_list'] = CommonService::getOutpatientTypeList(1);
        $data['condition']['tags_list'] = CommonService::getTagsList();
        $data['condition']['patient_diseases_list'] = CommonService::getDiseasesList(0, null, 1);

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/patient-assistant-list 患者列表【医助列表】
     * @apiName patient-assistant-list
     * @apiGroup Index
     *
     * @apiParam {String} start_time                                       开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                         结束时间【格式：2020-01-01】
     * @apiParam {String} keywords                                         关键词【姓名or手机号】
     * @apiParam {Number} belong_assistant_id                              咨询归属人
     * @apiParam {Number} outpatient_type_id                               就诊类型
     * @apiParam {Number} effect_type_id                                   效果类型
     * @apiParam {Number} risk_type_id                                     风控类型
     * @apiParam {Number} clinic_assess_id                                 诊疗评估类型
     * @apiParam {String} body_parts_ids                                   部位IDs【多个用','分割】
     * @apiParam {String} tags_ids                                         标签IDs【多个用','分割】
     * @apiParam {Number} clinic_id                                        门诊ID
     * @apiParam {String} patient_card_id                                  诊疗号
     * @apiParam {Number} fault_diagnosis_type                             断诊次数类型【1一次、2两次、3三次、4四次以上】
     * @apiParam {Number} sort_last_revisiting_type                        上次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_revisiting_type                        下次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_last_callback_type                          上次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_callback_type                          下次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_revisiting_type                             复诊次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_callback_type                               回访次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_missed_type                                 未到诊天数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页显示数量
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     患者列表
     * @apiSuccess {Number}  data.list.id                                  患者ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {String}  data.list.name                                患者姓名
     * @apiSuccess {Number}  data.list.age                                 患者年龄
     * @apiSuccess {Number}  data.list.gender                              患者性别
     * @apiSuccess {String}  data.list.gender_str                          患者性别值
     * @apiSuccess {String}  data.list.patient_card_id                     诊疗号
     * @apiSuccess {String}  data.list.clinic_name                         诊室名称
     * @apiSuccess {String}  data.list.mobile                              手机号
     * @apiSuccess {String}  data.list.last_revisiting_time_str            上次到诊时间
     * @apiSuccess {String}  data.list.next_revisiting_time_str            下次到诊时间
     * @apiSuccess {String}  data.list.last_callback_time_str              上次回访时间
     * @apiSuccess {String}  data.list.next_callback_time_str              下次回访时间
     * @apiSuccess {Number}  data.list.outpatient_type_id                  就诊类型ID
     * @apiSuccess {String}  data.list.outpatient_name                     就诊类型值
     * @apiSuccess {Array}   data.list.patient_tags_name_arr               患者标签数组
     * @apiSuccess {Number}  data.list.revisiting_count                    复诊次数
     * @apiSuccess {Number}  data.list.callback_count                      回访次数
     * @apiSuccess {Number}  data.list.missed_count                        未到诊天数
     * @apiSuccess {String}  data.list.city_name                           地区
     * @apiSuccess {Number}  data.list.source_channel_id                   来源ID
     * @apiSuccess {String}  data.list.source_name                         来源值
     * @apiSuccess {String}  data.list.remark                              备注
     * @apiSuccess {Number}  data.list.fault_diagnosis_count               断诊次数
     * @apiSuccess {String}  data.list.diseases_name                       病种
     * @apiSuccess {Array}   data.condition                                筛选条件
     * @apiSuccess {Array}   data.condition.member_medical_list            医助归属人
     * @apiSuccess {Number}  data.condition.member_medical_list.id         ID
     * @apiSuccess {String}  data.condition.member_medical_list.name       名称
     * @apiSuccess {Array}   data.condition.outpatient_type_list           就诊类型【同上】
     * @apiSuccess {Array}   data.condition.effect_type_list               效果类型【同上】
     * @apiSuccess {Array}   data.condition.risk_type_list                 风控类型【同上】
     * @apiSuccess {Array}   data.condition.clinic_assess_list             诊疗评估类型【同上】
     * @apiSuccess {Array}   data.condition.body_parts_list                部位【同上】
     * @apiSuccess {Array}   data.condition.tags_list                      标签【同上】
     * @apiSuccess {Array}   data.tab_totals                               tab统计数量
     * @apiSuccess {Number}  data.tab_totals.all_num                       全部
     * @apiSuccess {Number}  data.tab_totals.arrive_num                    已到
     * @apiSuccess {Number}  data.tab_totals.order_arrive_num              预到
     * @apiSuccess {Number}  data.tab_totals.unarrive_num                  未到
     */
    public function actionPatientAssistantList()
    {
        $params = Yii::$app->request->get();

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientUser->getListPage($params, (int)$page, (int)$pageSize, 2);

        // 格式化列表数据
        $data['list'] = Yii::$app->services->patientUser->getListPageFormat($data['list'], 2);

        // 获取筛选条件
        $params = [
            // 'get_body_parts' => 1,
            'get_body_parts_business' => 1,
            // 'get_member' => 1,
            'get_medical_member' => 1,
            'get_effect_type' => 1,
            'get_risk_type' => 1,
            'get_clinic_assess' => 1,
            'get_clinic' => 1,
            'get_hospital' => 1,
            'get_source_channel' => 1,
        ];
        $data['condition'] = Yii::$app->services->patientUser->getConditionList($params, $this->projectId, $data['is_check_type']);
        $data['condition']['outpatient_type_list'] = CommonService::getOutpatientTypeList(0);
        $data['condition']['tags_list'] = CommonService::getTagsList();
        $data['condition']['patient_diseases_list'] = CommonService::getDiseasesList(0, null, 1);

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/allot-patient-list 分配患者列表
     * @apiName allot-patient-list
     * @apiGroup Index
     *
     * @apiParam {String} start_time                                       开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                         结束时间【格式：2020-01-01】
     * @apiParam {String} source_channel_id                                来源渠道【多个用','分割】
     * @apiParam {String} belong_member_id                                 归属人【多个用','分割】
     * @apiParam {Number} gender                                           性别【0不详、1男、2女】
     * @apiParam {String} outpatient_type_id                               就诊类型【多个用','分割】
     * @apiParam {String} tags_ids                                         标签IDs【多个用','分割】
     * @apiParam {String} effect_type_id                                   效果类型【多个用','分割】
     * @apiParam {String} risk_type_id                                     风控类型【多个用','分割】
     * @apiParam {String} city_id                                          城市ID【多个用','分割】
     * @apiParam {Number} min_age                                          最小年龄
     * @apiParam {Number} max_age                                          最大年龄
     * @apiParam {Number} is_seas_patient                                  是否为公海用户【1是、0否】
     * @apiParam {String} clinic_id                                        诊室ID【多个用','分割】
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     患者列表
     * @apiSuccess {Number}  data.list.id                                  患者ID
     */
    public function actionAllotPatientList()
    {
        $params = Yii::$app->request->get();
        $params['project_id'] = $this->projectId;
        $params['is_seas_patient'] = $params['is_seas_patient'] ?? 0;

        // 查询结果
        $data = Yii::$app->services->patientUser->getAllotList($params);

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/allot-condition-list 获取分配患者筛选条件列表
     * @apiName allot-condition-list
     * @apiGroup Index
     *
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Array}   data.condition                                筛选条件
     * @apiSuccess {Array}   data.condition.source_channel_list            来源渠道
     * @apiSuccess {Number}  data.condition.source_channel_list.id         ID
     * @apiSuccess {String}  data.condition.source_channel_list.name       名称
     * @apiSuccess {Array}   data.condition.gender_list                    性别【同上】
     * @apiSuccess {Array}   data.condition.city_list                      城市【同上】
     * @apiSuccess {Array}   data.condition.tags_list                      标签【同上】
     * @apiSuccess {Array}   data.condition.member_list                    归属人【同上】
     * @apiSuccess {Array}   data.condition.effect_type_list               效果类型【同上】
     * @apiSuccess {Array}   data.condition.risk_type_list                 风控类型【同上】
     * @apiSuccess {Array}   data.condition.outpatient_type_list           就诊类型【同上】
     * @apiSuccess {Array}   data.condition.clinic_list                    诊室【同上】
     */
    public function actionAllotConditionList()
    {
        $data = [];

        // 获取筛选条件
        $params = [
            'get_source_channel' => 1,
            'get_gender' => 1,
            // 'get_city' => 1,
            'get_allot_member' => 1,
            'get_effect_type' => 1,
            'get_risk_type' => 1,
            'get_clinic' => 1,
        ];
        $condition = Yii::$app->services->patientUser->getConditionList($params, $this->projectId);
        $condition['member_list'] = $condition['member_allot_list'];
        $condition['outpatient_type_list'] = CommonService::getOutpatientTypeList(0);
        $data['condition']['tags_list'] = CommonService::getTagsList();
        unset($condition['member_allot_list']);

        $data['condition'] = $condition;

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/info 患者详情
     * @apiName info
     * @apiGroup Index
     *
     * @apiParam {Number} id                                            患者ID
     * @apiParam {Number} type                                          类型【1客服、2医助、3其他】
     *
     * @apiSuccess {Object}     data                                    返回数据
     * @apiSuccess {Number}     data.id                                 患者ID
     * @apiSuccess {Number}     data.project_id                         项目ID
     * @apiSuccess {Number}     data.patient_card_id                    诊疗号
     * @apiSuccess {Number}     data.name                               姓名
     * @apiSuccess {Number}     data.age                                年龄
     * @apiSuccess {Number}     data.gender                             性别
     * @apiSuccess {String}     data.gender_str                         性别值
     * @apiSuccess {Number}     data.belong_assistant_id                医助归属人ID
     * @apiSuccess {String}     data.belong_assistant_name              医助归属人姓名
     * @apiSuccess {Number}     data.belong_member_id                   客服归属人ID
     * @apiSuccess {String}     data.belong_member_name                 归属人姓名
     * @apiSuccess {String}     data.effect_type_str                    效果类型
     * @apiSuccess {String}     data.risk_type_str                      风控类型
     * @apiSuccess {String}     data.clinic_assess_str                  诊疗评估类型
     * @apiSuccess {String}     data.source_name_str                    来源渠道
     * @apiSuccess {String}     data.mobile                             手机
     * @apiSuccess {String}     data.city_name                          城市
     * @apiSuccess {String}     data.address                            详细地址
     * @apiSuccess {String}     data.outpatient_name                    就诊类型名称
     * @apiSuccess {String}     data.clinic_name                        诊室名
     * @apiSuccess {Array}      data.body_parts_name_arr                部位【数组】
     * @apiSuccess {Array}      data.tags_name_arr                      标签【数组】
     * @apiSuccess {String}     data.diseases_name                      病种
     * @apiSuccess {String}     data.remark                             备注
     * @apiSuccess {Number}     data.callback_count                     回访次数
     * @apiSuccess {Number}     data.revisiting_count                   复诊次数
     * @apiSuccess {Number}     data.fault_diagnosis_count              断诊次数
     * @apiSuccess {Number}     data.is_anti_relapse                    是否为抗复发【1是、0否】
     * @apiSuccess {String}     data.kf_next_callback_time_str          客服下次回访时间
     * @apiSuccess {String}     data.yz_next_callback_time_str          医助下次回访时间
     * @apiSuccess {String}     data.next_revisiting_time_str           下次复诊时间
     * @apiSuccess {String}     data.reg_time_str                       初次挂号时间【创建时间】
     * @apiSuccess {String}     data.created_at_str                     上次来院时间
     * @apiSuccess {Number}     data.reality_money                      患者消费金额
     * @apiSuccess {Number}     data.is_show_customer                   是否展示客服回访时间【1是、0否】
     * @apiSuccess {Number}     data.is_show_medical                    是否展示医助回访时间【1是、0否】
     * @apiSuccess {Number}     data.is_customer                        是否客服【1是、0否】
     * @apiSuccess {Number}     data.is_show_anti                       是否显示抗复发【1是、0否】
     */
    public function actionInfo()
    {
        $id = (int)Yii::$app->request->get('id', 0);
        $type = (int)Yii::$app->request->get('type', 3);

        return Yii::$app->services->patientUser->detail($id, $this->projectId, $type);
    }

    /**
     * @api {get} /v1/patient/index/edit-info 患者编辑详情
     * @apiName edit-info
     * @apiGroup Index
     *
     * @apiParam {Number} id                                                患者ID
     * @apiParam {Number} edit_type                                         类型【1客服、2医助、3其他】
     *
     * @apiSuccess {Object}     data                                        返回数据
     * @apiSuccess {Number}     data.id                                     患者ID
     * @apiSuccess {String}     data.project_id                             项目ID
     * @apiSuccess {Number}     data.patient_card_id                        诊疗号
     * @apiSuccess {String}     data.name                                   患者姓名
     * @apiSuccess {Number}     data.age                                    患者年龄
     * @apiSuccess {Number}     data.gender                                 患者性别
     * @apiSuccess {String}     data.birthday                               患者生日
     * @apiSuccess {String}     data.nickname                               昵称
     * @apiSuccess {String}     data.wx_name                                微信号
     * @apiSuccess {Number}     data.source_channel_id                      来源渠道ID
     * @apiSuccess {String}     data.mobile                                 手机号
     * @apiSuccess {Number}     data.city_id                                城市ID
     * @apiSuccess {String}     data.city_name                              城市
     * @apiSuccess {String}     data.address                                详细地址
     * @apiSuccess {Number}     data.patient_diseases_id                    病种ID
     * @apiSuccess {Number}     data.patient_diseases_child_id              二级病种ID
     * @apiSuccess {Array}      data.body_parts_ids                         部位IDs【数组】
     * @apiSuccess {Array}      data.tags_ids                               标签IDs【数组】
     * @apiSuccess {Number}     data.belong_assistant_id                    医助归属人ID
     * @apiSuccess {Number}     data.belong_member_id                       归属人ID
     * @apiSuccess {Number}     data.effect_type_id                         效果类型ID
     * @apiSuccess {Number}     data.risk_type_id                           风控类型ID
     * @apiSuccess {Number}     data.clinic_assess_id                       诊疗评估ID
     * @apiSuccess {Number}     data.outpatient_type_id                     就诊类型ID
     * @apiSuccess {Number}     data.clinic_id                              诊室ID
     * @apiSuccess {String}     data.profession                             职业
     * @apiSuccess {String}     data.kf_next_callback_time                  客服下次回访时间【is_show_customer=1 显示】
     * @apiSuccess {String}     data.yz_next_callback_time                  医助下次回访时间【is_show_medical=1 显示】
     * @apiSuccess {String}     data.next_revisiting_time                   下次复诊时间
     * @apiSuccess {Number}     data.is_anti_relapse                        是否为抗复发【1是、0否】
     * @apiSuccess {String}     data.remark                                 备注
     * @apiSuccess {Number}     data.is_show_customer                       是否显示客服归属人【1是、0否】
     * @apiSuccess {Number}     data.is_show_medical                        是否显示客服归属人【1是、0否】
     * @apiSuccess {Object}     data.condition                              筛选条件
     * @apiSuccess {Array}      data.condition.source_channel_list          来源渠道列表
     * @apiSuccess {Number}     data.condition.source_channel_list.id       ID
     * @apiSuccess {String}     data.condition.source_channel_list.name     名称
     * @apiSuccess {Array}      data.condition.city_list                    城市列表【同上】
     * @apiSuccess {Array}      data.condition.patient_diseases_list        一级病种列表【同上】
     * @apiSuccess {Array}      data.condition.patient_diseases_child_list  二级病种列表【同上】
     * @apiSuccess {Array}      data.condition.body_parts_list              部位列表【同上】
     * @apiSuccess {Array}      data.condition.tags_list                    标签列表【同上】
     * @apiSuccess {Array}      data.condition.member_customer_list         客服归属人列表【同上】
     * @apiSuccess {Array}      data.condition.member_medical_list          医助归属人列表【同上】
     * @apiSuccess {Array}      data.condition.effect_type_list             效果类型列表【同上】
     * @apiSuccess {Array}      data.condition.risk_type_list               风控类型列表【同上】
     * @apiSuccess {Array}      data.condition.clinic_assess_list           诊疗评估类型列表【同上】
     * @apiSuccess {Array}      data.condition.outpatient_type_list         就诊类型列表【同上】
     * @apiSuccess {Array}      data.condition.clinic_list                  诊室列表【同上】
     * @apiSuccess {Array}      data.condition.callback_status_list         回访状态列表【同上】
     */
    public function actionEditInfo()
    {
        $id = (int)Yii::$app->request->get('id', 0);
        $editType = (int)Yii::$app->request->get('edit_type', 3);

        return Yii::$app->services->patientUser->editInfo($id, $this->projectId, $editType);
    }

    /**
     * @api {get} /v1/patient/index/member-list 获取归属人列表
     * @apiName member-list
     * @apiGroup Index
     *
     * @apiParam {Number} id                                            患者ID
     *
     * @apiSuccess {Object}     data                                    返回数据
     * @apiSuccess {Array}      data.member_list                        归属人
     * @apiSuccess {Number}     data.member_list.id                     归属人ID
     * @apiSuccess {String}     data.member_list.name                   归属人姓名
     */
    public function actionMemberList()
    {
        // 获取筛选条件
        $params = [
            'get_member' => 2,
        ];
        $isCheckType = Yii::$app->user->identity->member->is_super == Member::IS_SUPER_YES ? 0 : 1;

        $condition = Yii::$app->services->patientUser->getConditionList($params, $this->projectId, $isCheckType);

        return $condition;
    }

    /**
     * @api {get} /v1/patient/index/doctor-guide-list 导医列表
     * @apiName doctor-guide-patient
     * @apiGroup Index
     *
     * @apiParam {String} start_time                                       开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                         结束时间【格式：2020-01-01】
     * @apiParam {String} keywords                                         关键词【姓名or手机号】
     * @apiParam {Number} source_channel_id                                来源渠道ID
     * @apiParam {Number} clinic_id                                        门诊ID
     * @apiParam {Number} sort                                             排序[1 = 倒叙 2 = 正序]
     * @apiParam {Number} patient_diseases_id                              病种ID
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页显示数
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     患者列表
     * @apiSuccess {Number}  data.list.id                                  患者ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {Number}  data.list.patient_card_id                     诊疗号
     * @apiSuccess {String}  data.list.name                                患者姓名
     * @apiSuccess {Number}  data.list.age                                 患者年龄
     * @apiSuccess {Number}  data.list.gender                              患者性别
     * @apiSuccess {String}  data.list.gender_str                          性别对应值
     * @apiSuccess {String}  data.list.clinic_name                         诊室名
     * @apiSuccess {String}  data.list.created_at_str                      到诊时间
     * @apiSuccess {String}  data.list.mobile                              手机号
     * @apiSuccess {String}  data.list.city_name                           所在城市
     * @apiSuccess {String}  data.list.diseases_name                       病种名
     * @apiSuccess {String}  data.list.source_name                         来源渠道名
     * @apiSuccess {Array}   data.condition                                筛选条件
     * @apiSuccess {Array}   data.condition.source_channel_list            来源渠道
     * @apiSuccess {Array}   data.condition.patient_diseases_list          病种列表
     */
    public function actionDoctorGuideList()
    {
        $params = Yii::$app->request->get();
        $params['project_id'] = $this->projectId;
        $params['start_time'] = $params['start_time'] ?? date('Y-m-d');
        $params['end_time'] = $params['end_time'] ?? date('Y-m-d');
        /*if (!$params['start_time'] && !$params['end_time']) {
            $nowDate = date('Y-m-d');
            $params['start_time'] = $nowDate;
            $params['end_time'] = $nowDate.' 23:59:59';
        }*/
        $params['sort'] = $params['sort'] ?? 1;
        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientUser->doctorGuideList($params, (int)$page, (int)$pageSize);

        // 格式化数据
        $data['list'] = Yii::$app->services->patientUser->doctorGuideListFormat($data['list']);

        // 获取筛选条件
        $params = [
            'get_source_channel' => 1,
            'get_clinic' => 1,
        ];
        $data['condition'] = Yii::$app->services->patientUser->getConditionList($params, $this->projectId);
        $data['condition']['patient_diseases_list'] = CommonService::getDiseasesList();

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/foot-print-list 用户足迹
     * @apiName foot-print-list
     * @apiGroup Index
     *
     * @apiParam {Number} patient_user_id                                  患者ID
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页显示数
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     列表
     * @apiSuccess {Number}  data.list.id                                  ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {Number}  data.list.patient_user_id                     患者ID
     * @apiSuccess {Number}  data.list.action_type                         类型
     * @apiSuccess {String}  data.list.action_type_str                     类型值
     * @apiSuccess {String}  data.list.action_content                      记录内容
     * @apiSuccess {String}  data.list.operate_name                        操作人姓名
     * @apiSuccess {String}  data.list.profession_name                     岗位名称
     * @apiSuccess {String}  data.list.created_at_str                      创建时间
     * @apiSuccess {String}  data.list.callback_way_str                    回访方式
     */
    public function actionFootPrintList()
    {
        $params = Yii::$app->request->get();
        $params['patient_user_id'] = $params['patient_user_id'] ?? 0;
        $params['project_id'] = $this->projectId;
        $params['action_type'] = [OperateLog::ACTION_TYPE_PATIENT_UPDATE, OperateLog::ACTION_TYPE_PATIENT_FOLLOW, OperateLog::ACTION_TYPE_PATIENT_TREATMENT];

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientOperateLog->getOperateLogPage($params, (int)$page, (int)$pageSize);

        // 格式化数据
        $data['list'] = Yii::$app->services->patientOperateLog->getOperateLogPageFormat($data['list']);

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/callback-list 回访列表
     * @apiName callback-list
     * @apiGroup Index
     *
     * @apiParam {Number} patient_user_id                                  患者ID
     * @apiParam {String} start_time                                       开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                         结束时间【格式：2020-01-01】
     * @apiParam {Number} profession_id                                    岗位ID
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页显示数
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     列表
     * @apiSuccess {Number}  data.list.id                                  ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {Number}  data.list.patient_user_id                     患者ID
     * @apiSuccess {Number}  data.list.callback_state_id                   回访类型ID
     * @apiSuccess {String}  data.list.callback_state                      回访类型值
     * @apiSuccess {String}  data.list.content                             回访内容
     * @apiSuccess {Number}  data.list.member_id                           操作人ID
     * @apiSuccess {String}  data.list.member_name                         操作人姓名
     * @apiSuccess {String}  data.list.profession_name                     岗位名称
     * @apiSuccess {String}  data.list.current_callback_time_str           本次回访时间
     * @apiSuccess {Array}   data.statistics_list                          统计结果
     * @apiSuccess {Number}  data.statistics_list.callback_state_id        回访类型ID
     * @apiSuccess {String}  data.statistics_list.callback_state           回访类型值
     * @apiSuccess {Number}  data.statistics_list.total                    总数
     * @apiSuccess {Array}   data.condition                                筛选条件
     * @apiSuccess {Array}   data.condition.permission_list                岗位列表
     * @apiSuccess {Number}  data.condition.permission_list.id             ID
     * @apiSuccess {String}  data.condition.permission_list.name           名称
     */
    public function actionCallbackList()
    {

        // 医助&&客服
        $allProfessionIds = [Profession::ID_MEDICAL, Profession::ID_CUSTOMER];

        $params = Yii::$app->request->get();
        $params['patient_user_id'] = $params['patient_user_id'] ?? 0;
//        $params['profession_id'] = isset($params['profession_id']) && $params['profession_id'] ? $params['profession_id'] : $allProfessionIds;
        $params['project_id'] = $this->projectId;

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientCallback->getPatientListPage2($params, (int)$page, (int)$pageSize);

//        $data = Yii::$app->services->patientCallback->getPatientListPage1($params, (int)$page, (int)$pageSize);
        // 格式化数据
        $data['list'] = Yii::$app->services->patientCallback->getPatientListPageFormat($data['list']);

        // 统计类型结果
        $data['statistics_list'] = Yii::$app->services->patientCallback->getPatientStatusList($params);

        // 岗位列表
        $data['condition']['permission_list'] = Yii::$app->services->profession->findList([
            'select' => ['id', 'name'],
            'id' => $allProfessionIds,
            'status' => Profession::STATUS_ENABLE,
        ]);
        // 风控类型
        $data['condition']['risk_type_list'] = Yii::$app->services->patientUser->getConditionList(['get_risk_type' => 1], $this->projectId)['risk_type_list'];
        // 效果类型
        $data['condition']['effect_type_list'] = Yii::$app->services->patientUser->getConditionList(['get_effect_type' => 1], $this->projectId)['effect_type_list'];

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/medical-list 病历辅助列表
     * @apiName medical-list
     * @apiGroup Index
     *
     * @apiParam {Number} patient_user_id                                  患者ID
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页显示数
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     列表
     * @apiSuccess {Number}  data.list.id                                  ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {Number}  data.list.patient_user_id                     患者ID
     * @apiSuccess {Number}  data.list.desc                                描述
     * @apiSuccess {String}  data.list.operate_id                          操作人ID
     * @apiSuccess {String}  data.list.operate_name                        操作人姓名
     * @apiSuccess {String}  data.list.profession_name                     岗位名称
     * @apiSuccess {String}  data.list.created_at_str                      操作时间
     */
    public function actionMedicalList()
    {
        $params = Yii::$app->request->get();
        $params['patient_user_id'] = $params['patient_user_id'] ?? 0;
        $params['project_id'] = $this->projectId;

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientMedicalAuxiliary->getListPage($params, (int)$page, (int)$pageSize);

        // 格式化数据
        $data['list'] = Yii::$app->services->patientMedicalAuxiliary->getListPageFormat($data['list']);

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/medical-info 病历信息
     * @apiName medical-info
     * @apiGroup Index
     *
     * @apiParam {Number} patient_user_id                               患者ID
     *
     * @apiSuccess {Object}  data                                       返回数据
     * @apiSuccess {Number}  data.id                                    ID
     * @apiSuccess {Number}  data.project_id                            项目ID
     * @apiSuccess {Number}  data.patient_user_id                       患者ID
     * @apiSuccess {Number}  data.sick_time_str                         生病时间
     * @apiSuccess {String}  data.main_desc                             主诉
     * @apiSuccess {String}  data.now_medical_history                   现病史
     * @apiSuccess {String}  data.allergy_history                       过敏史
     * @apiSuccess {String}  data.auxiliary_result                      辅助检查结果
     * @apiSuccess {String}  data.clinic_opinion                        治疗意见
     * @apiSuccess {String}  data.patient_diseases_id                   病种ID
     * @apiSuccess {String}  data.diseases_name                         病种名
     * @apiSuccess {Array}   data.condition                             筛选条件
     * @apiSuccess {Array}   data.condition.patient_diseases_list       病种列表
     * @apiSuccess {Number}  data.condition.patient_diseases_list.id    ID
     * @apiSuccess {String}  data.condition.patient_diseases_list.name  名称
     */
    public function actionMedicalInfo()
    {
        $params = Yii::$app->request->get();
        $params['patient_user_id'] = $params['patient_user_id'] ?? 0;

        // 病历信息
        $medicalRecord = Yii::$app->services->patientMedicalRecords->findInfo([
            'project_id' => $this->projectId,
            'patient_user_id' => $params['patient_user_id'],
        ]);

        // 病种列表
        $condition = [
            'patient_diseases_list' => CommonService::getDiseasesList(null),
        ];

        return [
            'id' => $medicalRecord->id ?? 0,
            'project_id' => $medicalRecord->project_id ?? 0,
            'patient_user_id' => $medicalRecord->patient_user_id ?? 0,
            'sick_time_str' => isset($medicalRecord->sick_time) && $medicalRecord->sick_time ? date('Y-m-d', $medicalRecord->sick_time) : '',
            'main_desc' => $medicalRecord->main_desc ?? '',
            'now_medical_history' => $medicalRecord->now_medical_history ?? '',
            'allergy_history' => $medicalRecord->allergy_history ?? '',
            'auxiliary_result' => $medicalRecord->auxiliary_result ?? '',
            'clinic_opinion' => $medicalRecord->clinic_opinion ?? '',
            'patient_diseases_id' => $medicalRecord->patient_diseases_id ?? 0,
            'diseases_name' => $medicalRecord->diseases_name ?? '',
            'condition' => $condition,
            'jw_history' => $medicalRecord->jw_history ?? '',
            'person_history' => $medicalRecord->person_history ?? '',
            'family_history' => $medicalRecord->family_history ?? '',
            'physique_history' => $medicalRecord->physique_history ?? '',
            'diagnose' => $medicalRecord->diagnose ?? '',
        ];
    }

    /**
     * @api {get} /v1/patient/index/treatment-list 治疗信息列表
     * @apiName treatment-list
     * @apiGroup Index
     *
     * @apiParam {Number} patient_user_id                                  患者ID
     * @apiParam {Number} patient_card_id                                  患者诊疗号
     * @apiParam {Number} clinic_project_id                                治疗项目ID
     * @apiParam {Number} data_type                                        数据类型【1治疗项目、2输液大厅】
     * @apiParam {String} clinic_date                                      治疗日期【格式：2022-01-01】
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页展示数
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     列表
     * @apiSuccess {Number}  data.list.id                                  治疗ID【type=1】
     * @apiSuccess {Number}  data.list.patient_card_id                     患者诊疗号
     * @apiSuccess {String}  data.list.clinic_project_name                 治疗项目名称
     * @apiSuccess {Number}  data.list.clinic_num                          本次使用数
     * @apiSuccess {Number}  data.list.total_num                           本次剩余数【type=1】
     * @apiSuccess {Number}  data.list.type                                类型【1治疗、2购买（新增）】
     * @apiSuccess {String}  data.list.operate_name                        操作人姓名【type=1】
     * @apiSuccess {String}  data.list.profession_name                     岗位【type=1】
     * @apiSuccess {String}  data.list.created_at_str                      治疗时间
     */
    public function actionTreatmentList()
    {
        $params = Yii::$app->request->get();
        $params['patient_user_id'] = $params['patient_user_id'] ?? 0;
        $params['patient_card_id'] = $params['patient_card_id'] ?? '';
        $params['clinic_project_id'] = $params['clinic_project_id'] ?? 0;
        $params['data_type'] = $params['data_type'] ?? 0;
        $params['clinic_date'] = $params['clinic_date'] ?? '';

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientUser->getTreatmentList($params, (int)$page, (int)$pageSize);

        // 格式化数据
        $data['list'] = Yii::$app->services->patientUser->getTreatmentListFormat($data['list']);

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/treatment-total 获取患者治疗统计信息
     * @apiName treatment-total
     * @apiGroup Index
     *
     * @apiParam {Number} patient_user_id                                  患者ID
     * @apiParam {Number} patient_card_id                                  患者诊疗号
     *
     * @apiSuccess {Object}  data                                          返回数据
     */
    public function actionTreatmentTotal()
    {
        $params = Yii::$app->request->get();
        $id = intval($params['patient_user_id'] ?? 0);
        $params['patient_card_id'] = $params['patient_card_id'] ?? '';

        // 统计总数
        return Yii::$app->services->clinicUserTreatment->getPatientProjectNum($params['patient_card_id'], $id);
    }

    /**
     * @api {get} /v1/patient/index/treatment-info 治疗信息详情
     * @apiName treatment-info
     * @apiGroup Index
     *
     * @apiParam {Number} id                                            治疗ID
     *
     * @apiSuccess {Object}  data                                       返回数据
     * @apiSuccess {Number}  data.id                                    治疗ID
     * @apiSuccess {Number}  data.clinic_num                            本次使用数
     * @apiSuccess {Number}  data.total_num                             本次剩余数
     * @apiSuccess {String}  data.dose                                  剂量【template=2\4】
     * @apiSuccess {String}  data.body_parts_large_name                 部位名称【template=4】
     * @apiSuccess {String}  data.patient_signature                     患者签名
     * @apiSuccess {String}  data.recently_clinic_time_str              治疗时间
     * @apiSuccess {Number}  data.template                              治疗项目模板【1:308模板、2：311模板、3其他、4半舱311】
     * @apiSuccess {Array}   data.deteail_list                          明细列表
     * @apiSuccess {Number}  data.deteail_list.id                       明细ID
     * @apiSuccess {String}  data.deteail_list.body_parts_large_name    大部位名称
     * @apiSuccess {String}  data.deteail_list.body_parts_small_name    细节部位名称
     * @apiSuccess {Number}  data.deteail_list.num                      数量
     * @apiSuccess {String}  data.deteail_list.dose                     剂量
     */
    public function actionTreatmentInfo()
    {
        $params = Yii::$app->request->get();
        $params['id'] = $params['id'] ?? 0;
        $params['project_id'] = $this->projectId;

        // 治疗信息
        $clinicTreatment = Yii::$app->services->clinicUserTreatment->findById((int)$params['id']);
        if (!$clinicTreatment) {
            return CommonHelper::api(422, '参数错误[id_error]');
        }

        // 治疗项目
        $clinicProject = Yii::$app->services->clinicProject->findById($clinicTreatment->clinic_project_id);

        // 治疗明细
        $clinicTreatmentDetailList = Yii::$app->services->clinicUserTreatmentDetail->findList([
            'select' => ['id', 'body_parts_large_name', 'body_parts_small_name', 'num', 'dose'],
            'clinic_treatment_id' => $params['id'],
        ]);

        return [
            'id' => $clinicTreatment->id,
            'clinic_num' => $clinicTreatment->recently_clinic_num + $clinicTreatment->recently_surplus_num,
            'total_num' => $clinicTreatment->total_num + $clinicTreatment->help_num,
            'dose' => $clinicProject && in_array($clinicProject->template, [Project::TEMPLATE_311, Project::TEMPLATE_HALF_311]) ? ($clinicTreatmentDetailList[0]['dose'] ?? '') : '',
            'body_parts_large_name' => $clinicProject && in_array($clinicProject->template, [Project::TEMPLATE_HALF_311]) ? ($clinicTreatmentDetailList[0]['body_parts_large_name'] ?? '') : '',
            'patient_signature' => ImageHelper::getImageUrl($clinicTreatment->patient_signature),
            'recently_clinic_time_str' => $clinicTreatment->recently_clinic_time ? date('Y-m-d H:i', $clinicTreatment->recently_clinic_time) : '',
            'template' => $clinicProject->template ?? 0,// 模板类型【1：308、2：311、3通用、4半舱311】
            'deteail_list' => $clinicTreatmentDetailList ?? [],
            'remark' => $clinicTreatment->remark ?? '',
        ];

    }

    /**
     * @api {get} /v1/patient/index/consumption-list 消费信息列表
     * @apiName consumption-list
     * @apiGroup Index
     *
     * @apiParam {String} patient_card_id                                  患者诊疗号
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页展示数
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     列表
     * @apiSuccess {Number}  data.list.id                                  ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {String}  data.list.patient_card_id                     患者诊疗号
     * @apiSuccess {Number}  data.list.consulting_room                     诊室名
     * @apiSuccess {String}  data.list.doctor_name                         医生名
     * @apiSuccess {String}  data.list.money                               实【收/退】金额
     * @apiSuccess {String}  data.list.reality_money                       应【收/退】金额
     * @apiSuccess {String}  data.list.trade_type                          类型【1入账、2退款】
     * @apiSuccess {String}  data.list.clinic_time_str                     就诊时间
     * @apiSuccess {String}  data.list.created_at_str                      收费/退费时间
     */
    public function actionConsumptionList()
    {
        $params = Yii::$app->request->get();
        $params['patient_card_id'] = $params['patient_card_id'] ?? '';
        $params['project_id'] = $this->projectId;

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientConsumption->getListPage($params, (int)$page, (int)$pageSize);

        // 格式化数据
        $data['list'] = Yii::$app->services->patientConsumption->getListPageFormat($data['list']);

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/consumption-info 消费信息明细
     * @apiName consumption-info
     * @apiGroup Index
     *
     * @apiParam {Number} consumption_id                                   消费信息ID
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     列表
     * @apiSuccess {Number}  data.list.id                                  ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {String}  data.list.patient_card_id                     患者诊疗号
     * @apiSuccess {Number}  data.list.consulting_room                     诊室名
     * @apiSuccess {String}  data.list.doctor_name                         医生名
     * @apiSuccess {String}  data.list.money                               实【收/退】金额
     * @apiSuccess {String}  data.list.reality_money                       应【收/退】金额
     * @apiSuccess {String}  data.list.trade_type                          类型【1入账、2退款】
     * @apiSuccess {String}  data.list.clinic_time_str                     就诊时间
     * @apiSuccess {String}  data.list.created_at_str                      收费/退费时间
     */
    public function actionConsumptionInfo()
    {
        $params = Yii::$app->request->get();
        $params['consumption_id'] = $params['consumption_id'] ?? 0;
        $params['project_id'] = $this->projectId;

        // 消费信息
        $consumption = Yii::$app->services->patientConsumption->findById((int)$params['consumption_id']);
        if (!$consumption) {
            return CommonHelper::api(422, '参数错误[id_error]');
        }

        // 查询结果
        $data = Yii::$app->services->patientConsumptionDetail->getListPage($params);

        // 格式化数据
        $data['list'] = Yii::$app->services->patientConsumptionDetail->getListPageFormat($data['list']);

        return [
            'id' => $consumption->id,
            'money' => $consumption->money,
            'reality_money' => $consumption->reality_money,
            'refund_money' => $consumption->refund_money,
            'detail_list' => $data['list'],
        ];
    }

    /**
     * @api {get} /v1/patient/index/clinic-img-list 治疗图片列表
     * @apiName clinic-img-list
     * @apiGroup Index
     *
     * @apiParam {Number} patient_card_id                                  患者诊疗号
     * @apiParam {String} body_parts_id                                    部位ID【多个','分割】
     * @apiParam {Number} sort_created_at_type                             创建时间排序【0默认、1顺序、2倒序】
     * @apiParam {String} img_date                                         图片日期【多个','分割】
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页展示数
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     列表
     * @apiSuccess {Number}  data.list.id                                  ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {Number}  data.list.patient_card_id                     患者诊疗号
     * @apiSuccess {Number}  data.list.img_url                             图片地址
     * @apiSuccess {String}  data.list.body_parts_id                       部位ID
     * @apiSuccess {String}  data.list.body_parts_name                     部位名称
     * @apiSuccess {String}  data.list.created_at_str                      操作时间
     * @apiSuccess {Array}   data.condition                                筛选列表
     * @apiSuccess {Array}   data.condition.body_parts_list                部位列表【绑定图片用】
     * @apiSuccess {Number}  data.condition.body_parts_list.id             ID
     * @apiSuccess {String}  data.condition.body_parts_list.name           名称
     * @apiSuccess {Array}   data.condition.select_body_parts_list         分类部位【同上，筛选用】
     */
    public function actionClinicImgList()
    {
        $params = Yii::$app->request->get();
        $params['patient_card_id'] = $params['patient_card_id'] ?? '';
        $params['img_date'] = isset($params['img_date']) && $params['img_date'] ? explode(',', $params['img_date']) : [];
        $params['project_id'] = $this->projectId;

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientClinicImg->getListPage($params, (int)$page, (int)$pageSize);

        // 格式化数据
        $data['list'] = Yii::$app->services->patientClinicImg->getListPageFormat($data['list'], $this->projectId);

        // 患者部位
        $list = Yii::$app->services->patientClinicImg->findList([
            'select' => ['id', 'body_parts_id'],
            'project_id' => $this->projectId,
            'patient_card_id' => $params['patient_card_id'],
            'status' => ClinicImg::STATUS_ENABLE
        ]);

        // 病种列表
        $selectCondition = Yii::$app->services->patientUser->getConditionList([
            'get_body_parts' => 1,
            'body_parts_id' => array_column($list, 'body_parts_id'),
        ]);
        $condition = Yii::$app->services->patientUser->getConditionList([
            'get_body_parts' => 1,
        ]);
        $data['condition'] = [
            'select_body_parts_list' => $selectCondition['body_parts_list'],
            'body_parts_list' => $condition['body_parts_list'],
        ];

        $data['condition']['body_parts_list'] = $condition['body_parts_list'];

        // 图片日期
        $dateList = Yii::$app->services->patientClinicImg->getListDate($params);
        $data['condition']['date_list'] = array_column($dateList, 'img_date');

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/operate-log-list 操作日志
     * @apiName operate-log-list
     * @apiGroup Index
     *
     * @apiParam {Number} patient_user_id                                  患者ID
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页显示数
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     列表
     * @apiSuccess {Number}  data.list.id                                  ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {Number}  data.list.patient_user_id                     患者ID
     * @apiSuccess {Number}  data.list.action_type                         类型
     * @apiSuccess {String}  data.list.action_type_str                     类型值
     * @apiSuccess {String}  data.list.action_content                      记录内容
     * @apiSuccess {String}  data.list.operate_name                        操作人姓名
     * @apiSuccess {String}  data.list.profession_name                     岗位名称
     * @apiSuccess {String}  data.list.created_at_str                      创建时间
     */
    public function actionOperateLogList()
    {
        $params = Yii::$app->request->get();
        $params['patient_user_id'] = $params['patient_user_id'] ?? 0;
        $params['project_id'] = $this->projectId;
        $params['action_type'] = [OperateLog::ACTION_TYPE_PATIENT_UPDATE];

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientOperateLog->getOperateLogPage($params, $page, $pageSize);

        // 格式化数据
        $data['list'] = Yii::$app->services->patientOperateLog->getOperateLogPageFormat($data['list']);

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/search-diseases-list 搜索二级病种列表
     * @apiName search-diseases-list
     * @apiGroup Index
     *
     * @apiParam {Number} patient_diseases_id                              父病种ID
     *
     * @apiSuccess {Object}  data                                          返回
     * @apiSuccess {Array}   data.list                                     列表
     * @apiSuccess {Number}  data.list.id                                  病种ID
     * @apiSuccess {String}  data.list.name                                病种名称
     */
    public function actionSearchDiseasesList()
    {
        $params = Yii::$app->request->get();
        $params['patient_diseases_id'] = $params['patient_diseases_id'] ?? 0;
        $params['patient_diseases_child_id'] = $params['patient_diseases_child_id'] ?? null;

        $data = [];
        // 查询结果
        if ($params['patient_diseases_id'] > 0) {
            $data = Yii::$app->services->patientDiseases->findList([
                'select' => ['id', 'diseases_name AS name', 'status'],
                'pid' => $params['patient_diseases_id'],
                'status' => PatientDiseases::STATUS_ENABLE
            ], $params['patient_diseases_child_id']);
        }

        return [
            'list' => $data,
        ];
    }

    /**
     * @api {get} /v1/patient/index/anti-list 抗复发列表
     * @apiName anti-list
     * @apiGroup Index
     *
     * @apiParam {String} keywords                                         关键词
     * @apiParam {Number} clinic_id                                        诊室
     * @apiParam {Number} belong_assistant_id                              医助归属人
     * @apiParam {Number} outpatient_type_id                               就诊类型
     * @apiParam {Number} effect_type_id                                   效果类型
     * @apiParam {Number} risk_type_id                                     风控类型
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页展示数
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     患者列表
     * @apiSuccess {Number}  data.list.id                                  患者ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {String}  data.list.name                                患者姓名
     * @apiSuccess {Number}  data.list.age                                 患者年龄
     * @apiSuccess {Number}  data.list.gender                              患者性别
     * @apiSuccess {String}  data.list.gender_str                          患者性别值
     * @apiSuccess {String}  data.list.patient_card_id                     诊疗号
     * @apiSuccess {String}  data.list.clinic_name                         诊室名称
     * @apiSuccess {String}  data.list.mobile                              手机号
     * @apiSuccess {String}  data.list.last_revisiting_time_str            上次到诊时间
     * @apiSuccess {String}  data.list.next_revisiting_time_str            下次到诊时间
     * @apiSuccess {String}  data.list.last_callback_time_str              上次回访时间
     * @apiSuccess {String}  data.list.next_callback_time_str              下次回访时间
     * @apiSuccess {Number}  data.list.outpatient_type_id                  就诊类型ID
     * @apiSuccess {String}  data.list.outpatient_name                     就诊类型值
     * @apiSuccess {Array}   data.list.patient_tags_name_arr               患者标签数组
     * @apiSuccess {Number}  data.list.revisiting_count                    复诊次数
     * @apiSuccess {Number}  data.list.callback_count                      回访次数
     * @apiSuccess {Number}  data.list.missed_count                        未到诊天数
     * @apiSuccess {String}  data.list.city_name                           地区
     * @apiSuccess {Number}  data.list.source_channel_id                   来源ID
     * @apiSuccess {String}  data.list.source_name                         来源值
     * @apiSuccess {Number}  data.list.anti_relapse_year                   抗复发年限
     * @apiSuccess {String}  data.list.anti_relapse_year_str               抗复发年限对应值
     * @apiSuccess {String}  data.list.remark                              备注
     * @apiSuccess {Array}   data.condition                                筛选条件
     * @apiSuccess {Array}   data.condition.member_medical_list            医助归属人
     * @apiSuccess {Number}  data.condition.member_medical_list.id         ID
     * @apiSuccess {String}  data.condition.member_medical_list.name       名称
     * @apiSuccess {Array}   data.condition.outpatient_type_list           就诊类型【同上】
     * @apiSuccess {Array}   data.condition.effect_type_list               效果类型【同上】
     * @apiSuccess {Array}   data.condition.risk_type_list                 风控类型【同上】
     * @apiSuccess {Array}   data.condition.clinic_assess_list             诊疗评估类型【同上】
     * @apiSuccess {Array}   data.condition.body_parts_list                部位【同上】
     * @apiSuccess {Array}   data.condition.tags_list                      标签【同上】
     */
    public function actionAntiList()
    {
        $params = Yii::$app->request->get();
        $params['is_anti_relapse'] = User::IS_ANTI_RELAPSE_YES;

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientUser->getListPage($params, (int)$page, (int)$pageSize, 3);

        // 格式化列表数据
        $data['list'] = Yii::$app->services->patientUser->getListPageFormat($data['list'], 2);

        // 获取筛选条件
        $params = [
            'get_medical_member' => 1,
            'get_effect_type' => 1,
            'get_risk_type' => 1,
            'get_clinic' => 1,
        ];
        $data['condition'] = Yii::$app->services->patientUser->getConditionList($params, Yii::$app->params['project_id'], $data['is_check_type']);
        $data['condition']['outpatient_type_list'] = CommonService::getOutpatientTypeList(0);

        // 人员诊室
        $memberAttr = Yii::$app->services->member->findListInnerAttr([
            'member_id' => array_column($data['condition']['member_medical_list'], 'id'),
            'project_id' => $this->projectId
        ]);
        foreach ($memberAttr as $ma) {
            $memberAttr[$ma['id']] = $ma['clinic_id'];
        }
        // 整合数据返回医助诊室
        foreach ($data['condition']['member_medical_list'] as &$val) {
            if (isset($memberAttr[$val['id']])) {
                $val['clinic_id'] = $memberAttr[$val['id']];
            }
        }

        return $data;
    }

    /**
     * @api {post} /v1/patient/index/update 编辑患者
     * @apiName update
     * @apiGroup Index
     *
     * @apiParam {Number} edit_type                  编辑类型【1客服、2医助、3其他】
     * @apiParam {Number} id                         患者ID
     * @apiParam {String} name                       患者姓名【必填】
     * @apiParam {String} birthday                   患者生日
     * @apiParam {Number} age                        患者年龄
     * @apiParam {String} nickname                   微信昵称
     * @apiParam {String} wx_name                    微信号
     * @apiParam {Number} source_channel_id          来源渠道ID
     * @apiParam {Number} gender                     患者性别【0不详、1男、2女】
     * @apiParam {Number} mobile                     手机号【必填】
     * @apiParam {Number} city_id                    城市ID
     * @apiParam {String} address                    详细地址
     * @apiParam {Number} patient_diseases_id        一级病种ID
     * @apiParam {Number} patient_diseases_child_id  二级病种ID
     * @apiParam {String} body_parts_ids             部位IDs【多个用','分割】
     * @apiParam {String} tags_ids                   标签IDs【多个用','分割】
     * @apiParam {Number} belong_assistant_id        医助归属人ID【必填】
     * @apiParam {Number} belong_member_id           客服归属人ID【必填】
     * @apiParam {Number} effect_type_id             效果类型ID
     * @apiParam {Number} risk_type_id               风控类型ID
     * @apiParam {Number} clinic_assess_id           诊疗评估ID
     * @apiParam {Number} outpatient_type_id         就诊类型ID
     * @apiParam {Number} clinic_id                  诊室ID【必填】
     * @apiParam {String} profession                 职业
     * @apiParam {String} kf_next_callback_time      客服下次回访时间【必填- 作废】
     * @apiParam {String} yz_next_callback_time      医助下次回访时间【必填- 作废】
     * @apiParam {String} next_revisiting_time       下次复诊时间【作废】
     * @apiParam {String} remark                     备注
     *
     * @apiSuccess {Object}  data                    返回数据
     * @apiSuccess {Number}  data.id                 患者ID
     */
    public function actionUpdatePatient()
    {
        $params = Yii::$app->request->post();
        $params['project_id'] = $this->projectId;
        $params['belong_assistant_id'] = intval($params['belong_assistant_id'] ?? 0);
        $params['belong_member_id'] = intval($params['belong_member_id'] ?? 0);
        $params['edit_type'] = $params['edit_type'] ?? 1;
        $params['city_id'] = intval($params['city_id'] ?? 0);
        // 检验类型【1客服、2医助、3其他（两者都检验）】
        $params['check_type'] = $params['edit_type'];

        if ($params['edit_type'] == 1) {// 客服
            $params['belong_assistant_id'] = 0;
        } elseif ($params['edit_type'] == 2) {// 医助
            $params['belong_member_id'] = 0;
        } else {
            $attr = Yii::$app->services->attr->findInfo([
                'member_id' => Yii::$app->user->identity->member_id,
                'project_id' => $this->projectId,
            ]);

            if ($attr) {
                if ($attr->profession_id == Profession::ID_MEDICAL) {// 医助
                    $params['belong_member_id'] = 0;
                    $params['check_type'] = 2;
                } elseif ($attr->profession_id == Profession::ID_CUSTOMER) {// 客服
                    $params['belong_assistant_id'] = 0;
                    $params['check_type'] = 1;
                } else {
                    $params['check_type'] = 3;
                }
            } else {
                $params['check_type'] = 3;
            }
        }

        $model = new PatientForm();
        $model->setScenario('edit');
        $model->attributes = $params;
        if (!$model->validate()) {
            // 返回数据验证失败
            return CommonHelper::api(422, $this->getError($model));
        }

        return Yii::$app->services->patientUser->edit($model, $params['check_type']);
    }

    /**
     * @api {post} /v1/patient/index/update-remark 编辑患者备注
     * @apiName update-remark
     * @apiGroup Index
     *
     * @apiParam {Number} id                         患者ID
     * @apiParam {String} remark                     备注
     *
     * @apiSuccess {Object}  data                    返回数据
     * @apiSuccess {Number}  data.id                 患者ID
     */
    public function actionUpdatePatientRemark()
    {
        $params = Yii::$app->request->post();
        $params['project_id'] = $this->projectId;
        $params['remark'] = $params['remark'] ?? '';

        $model = new PatientForm();
        $model->setScenario('edit_remark');
        $model->attributes = $params;
        if (!$model->validate()) {
            // 返回数据验证失败
            return CommonHelper::api(422, $this->getError($model));
        }

        return Yii::$app->services->patientUser->editRemark($model);
    }

    /**
     * @api {post} /v1/patient/index/allot-patient 患者分配
     * @apiName allot-patient
     * @apiGroup Index
     *
     * @apiParam {Number} id                         患者ID
     * @apiParam {Number} belong_member_id           归属人ID
     *
     * @apiSuccess {Object}  data                    返回数据
     * @apiSuccess {Number}  data.id                 患者ID
     */
    public function actionAllotPatient()
    {
        $params = Yii::$app->request->post();
        $params['project_id'] = $this->projectId;

        $model = new PatientForm();
        $model->setScenario('edit_member_id');
        $model->attributes = $params;
        if (!$model->validate()) {
            // 返回数据验证失败
            return CommonHelper::api(422, $this->getError($model));
        }

        return Yii::$app->services->patientUser->editBelongMember($model);
    }

    /**
     * @api {post} /v1/patient/index/allot-batch-patient 患者批量分配
     * @apiName allot-batch-patient
     * @apiGroup Index
     *
     * @apiParam {String} ids                        患者IDs【多个用','分割】
     * @apiParam {String} belong_member_ids          归属人IDs【多个用','分割】
     * @apiParam {Number} check_type                 类型【1客服、2医助】
     *
     * @apiSuccess {Object}  data                    返回数据
     * @apiSuccess {Number}  data.ids                患者IDs
     */
    public function actionAllotBatchPatient()
    {
        $params = Yii::$app->request->post();
        $params['project_id'] = $this->projectId;
        $params['check_type'] = $params['check_type'] ?? 1;

        $model = new PatientForm();
        $model->setScenario('edit_batch_member_id');
        $model->attributes = $params;
        if (!$model->validate()) {
            // 返回数据验证失败
            return CommonHelper::api(422, $this->getError($model));
        }

        return Yii::$app->services->patientUser->editBatchBelongMember($model);
    }

    /**
     * @api {post} /v1/patient/index/edit-medical 编辑病历
     * @apiName edit-medical
     * @apiGroup Index
     *
     * @apiParam {Number} patient_user_id            患者ID
     * @apiParam {String} sick_time                  生病时间【格式：2020-01-01】
     * @apiParam {String} main_desc                  主诉
     * @apiParam {String} now_medical_history        现病史
     * @apiParam {String} allergy_history            过敏史
     * @apiParam {String} jw_history                 既往史
     * @apiParam {String} person_history             个人史
     * @apiParam {String} family_history             家族史
     * @apiParam {String} physique_history           体格检查
     * @apiParam {String} diagnose                   诊断
     * @apiParam {String} auxiliary_result           辅助检查结果
     * @apiParam {String} clinic_opinion             治疗意见
     * @apiParam {Number} patient_diseases_id        病种ID
     *
     * @apiSuccess {Object}  data                    返回数据
     * @apiSuccess {Number}  data.id                 病历ID
     */
    public function actionEditMedical()
    {
        $params = Yii::$app->request->post();
        $params['project_id'] = $this->projectId;

        $params['sick_time'] = $params['sick_time'] ?? '';
        $params['main_desc'] = $params['main_desc'] ?? '';
        $params['now_medical_history'] = $params['now_medical_history'] ?? '';
        $params['allergy_history'] = $params['allergy_history'] ?? '';
        $params['jw_history'] = $params['jw_history'] ?? '';
        $params['person_history'] = $params['person_history'] ?? '';
        $params['family_history'] = $params['family_history'] ?? '';
        $params['physique_history'] = $params['physique_history'] ?? '';
        $params['diagnose'] = $params['diagnose'] ?? '';
        $params['auxiliary_result'] = $params['auxiliary_result'] ?? '';
        $params['clinic_opinion'] = $params['clinic_opinion'] ?? '';
        $params['patient_diseases_id'] = $params['patient_diseases_id'] ?? 0;
        if (!$params['sick_time'] && !$params['main_desc'] && !$params['now_medical_history'] && !$params['allergy_history'] && !$params['jw_history'] && !$params['person_history'] && !$params['family_history'] && !$params['physique_history'] && !$params['diagnose'] && !$params['auxiliary_result'] && !$params['clinic_opinion'] && !$params['patient_diseases_id']) {
            return CommonHelper::api(422, '请至少填写一项内容');
        }

        $model = new MedicalForm();
        $model->setScenario('edit');
        $model->attributes = $params;
        if (!$model->validate()) {
            // 返回数据验证失败
            return CommonHelper::api(422, $this->getError($model));
        }

        return Yii::$app->services->patientMedicalRecords->edit($model);
    }

    /**
     * @api {post} /v1/patient/index/edit-medical-noverify 编辑病历【对外无需验证】
     * @apiName edit-medical
     * @apiGroup Index
     *
     * @apiParam {Number} patient_card_id            患者诊疗号
     * @apiParam {String} sick_time                  生病时间【格式：2020-01-01】
     * @apiParam {String} main_desc                  主诉
     * @apiParam {String} now_medical_history        现病史
     * @apiParam {String} allergy_history            过敏史
     * @apiParam {String} jw_history                 既往史
     * @apiParam {String} person_history             个人史
     * @apiParam {String} family_history             家族史
     * @apiParam {String} physique_history           体格检查
     * @apiParam {String} diagnose                   诊断
     * @apiParam {String} auxiliary_result           辅助检查结果
     * @apiParam {String} clinic_opinion             治疗意见
     * @apiParam {Number} patient_diseases_id        病种ID
     *
     * @apiSuccess {Object}  data                    返回数据
     * @apiSuccess {Number}  data.id                 病历ID
     */
    public function actionEditMedicalNoverify()
    {
        $params = Yii::$app->request->post();
        $params['project_id'] = $this->projectId;

        $params['sick_time'] = $params['sick_time'] ?? '';
        $params['main_desc'] = $params['main_desc'] ?? '';
        $params['now_medical_history'] = $params['now_medical_history'] ?? '';
        $params['allergy_history'] = $params['allergy_history'] ?? '';
        $params['jw_history'] = $params['jw_history'] ?? '';
        $params['person_history'] = $params['person_history'] ?? '';
        $params['family_history'] = $params['family_history'] ?? '';
        $params['physique_history'] = $params['physique_history'] ?? '';
        $params['diagnose'] = $params['diagnose'] ?? '';
        $params['auxiliary_result'] = $params['auxiliary_result'] ?? '';
        $params['clinic_opinion'] = $params['clinic_opinion'] ?? '';
        $params['patient_diseases_id'] = $params['patient_diseases_id'] ?? 0;
        if (!$params['sick_time'] && !$params['main_desc'] && !$params['now_medical_history'] && !$params['allergy_history'] && !$params['jw_history'] && !$params['person_history'] && !$params['family_history'] && !$params['physique_history'] && !$params['diagnose'] && !$params['auxiliary_result'] && !$params['clinic_opinion'] && !$params['patient_diseases_id']) {
            return CommonHelper::api(422, '请至少填写一项内容');
        }

        $model = new MedicalForm();
        $model->setScenario('edit_out');
        $model->attributes = $params;
        if (!$model->validate()) {
            // 返回数据验证失败
            return CommonHelper::api(422, $this->getError($model));
        }

        return Yii::$app->services->patientMedicalRecords->edit($model);
    }

    /**
     * @api {post} /v1/patient/index/create-medical-auxiliary 新增病历辅助内容
     * @apiName create-medical-auxiliary
     * @apiGroup Index
     *
     * @apiParam {Number} patient_user_id            患者ID
     * @apiParam {String} desc                       内容
     *
     * @apiSuccess {Object}  data                    返回数据
     * @apiSuccess {Number}  data.id                 病历辅助内容ID
     */
    public function actionCreateMedicalAuxiliary()
    {
        $params = Yii::$app->request->post();
        $params['project_id'] = $this->projectId;

        $model = new MedicalForm();
        $model->setScenario('create-auxiliary');
        $model->attributes = $params;
        if (!$model->validate()) {
            // 返回数据验证失败
            return CommonHelper::api(422, $this->getError($model));
        }

        return Yii::$app->services->patientMedicalAuxiliary->create($model);
    }

    /**
     * @api {post} /v1/patient/index/edit-clinic-img 治疗图片绑定部位
     * @apiName edit-clinic-img
     * @apiGroup Index
     *
     * @apiParam {Number} patient_card_id           患者诊疗号
     * @apiParam {Json}   clinic_imgs               治疗图片json数据【[{id: '图片ID', body_parts_id: '部位ID'}] 】
     *
     * @apiSuccess {Object}  data                   返回数据
     * @apiSuccess {Number}  data.patient_card_id   患者诊疗号
     */
    public function actionEditClinicImg()
    {
        $params = Yii::$app->request->post();
        $params['project_id'] = $this->projectId;

        $model = new ClinicImgForm();
        $model->setScenario('edit');
        $model->attributes = $params;
        if (!$model->validate()) {
            // 返回数据验证失败
            return CommonHelper::api(422, $this->getError($model));
        }

        return Yii::$app->services->patientClinicImg->editBodyParts($model);
    }

    /**
     * @api {post} /v1/patient/index/delete-clinic-img 删除治疗图片
     * @apiName delete-clinic-img
     * @apiGroup Index
     *
     * @apiParam {String} ids                       治疗图片IDs【多个用','分割】
     *
     * @apiSuccess {Object}  data                   返回数据
     * @apiSuccess {String}  data.ids               治疗图片IDs
     */
    public function actionDeleteClinicImg()
    {
        $params = Yii::$app->request->post();
        $params['project_id'] = $this->projectId;

        $model = new ClinicImgForm();
        $model->setScenario('delete');
        $model->attributes = $params;
        if (!$model->validate()) {
            // 返回数据验证失败
            return CommonHelper::api(422, $this->getError($model));
        }

        return Yii::$app->services->patientClinicImg->delete($model, $this->projectId);
    }

    /**
     * @api {post} /v1/patient/index/update-anti 编辑患者抗复发状态
     * @apiName update-anti
     * @apiGroup Index
     *
     * @apiParam {Number} id                         患者ID
     * @apiParam {Number} is_anti_relapse            是否为抗复发【1是、0否】
     *
     * @apiSuccess {Object}  data                    返回数据
     * @apiSuccess {Number}  data.id                 患者ID
     */
    public function actionUpdateAnti()
    {
        $params = Yii::$app->request->post();
        $params['project_id'] = $this->projectId;

        $model = new PatientForm();
        $model->setScenario('edit_anti');
        $model->attributes = $params;
        if (!$model->validate()) {
            // 返回数据验证失败
            return CommonHelper::api(422, $this->getError($model));
        }

        return Yii::$app->services->patientUser->editAnti($model);
    }

    /**
     * @api {post} /v1/patient/index/update-anti-year 编辑患者抗复发年限
     * @apiName update-anti-year
     * @apiGroup Index
     *
     * @apiParam {Number} id                         患者ID
     * @apiParam {Number} anti_relapse_year          抗复发年限
     *
     * @apiSuccess {Object}  data                    返回数据
     * @apiSuccess {Number}  data.id                 患者ID
     */
    public function actionUpdateAntiYear()
    {
        $params = Yii::$app->request->post();
        $params['project_id'] = $this->projectId;

        $model = new PatientForm();
        $model->setScenario('edit_anti_year');
        $model->attributes = $params;
        if (!$model->validate()) {
            // 返回数据验证失败
            return CommonHelper::api(422, $this->getError($model));
        }

        return Yii::$app->services->patientUser->editAntiYear($model);
    }


    /**
     * @api {post} /v1/patient/index/update-follow 关注或取消关注患者
     * @apiName update-follow
     * @apiGroup Index
     *
     * @apiParam {Number} id                         患者ID
     * @apiParam {Number} follow_status          关注还是取消关注
     *
     * @apiSuccess {Object}  data                    返回数据
     * @apiSuccess {Number}  data.id                 患者ID
     */
    public function actionUpdateFollow()
    {
        $id = intval(Yii::$app->request->post('id'));
        $followStatus = intval(Yii::$app->request->post('follow_status'));
        $followStatus = $followStatus === 1 ? true : false;

        return Yii::$app->services->patientUser->updatePatientFollow($id, $followStatus);

    }

    /**
     * @api {get} /v1/patient/index/clinic-member 根据诊室id获取归属人
     * @apiName clinic-member
     * @apiGroup Index
     *
     * @apiParam {Number} clinic_id          诊室id
     * @apiParam {Number} edit_type          1：客服， 2：医助
     *
     * @apiSuccess {Object}  data            返回数据
     * @apiSuccess {Number}  data.value      归属人ID
     * @apiSuccess {Number}  data.title      归属人姓名
     */
    public function actionClinicMember()
    {
        $clinicId = intval(Yii::$app->request->get('clinic_id', 0));
        $editType = intval(Yii::$app->request->get('edit_type', 0));    // 1：客服， 2：医助
        $projectId = $this->projectId;

        return Yii::$app->services->patientUser->getMemberByClinicId($clinicId, $editType, $projectId);
    }

    /**
     * 获取患者标签列表及是否选择
     *
     * @return array
     * @author chenyuebin
     */
    public function actionTagsList()
    {
        $patient_id = Yii::$app->request->get('patient_id');
        $project_id = $this->projectId;

        // 标签列表
        $taglist = Yii::$app->services->marketingTags->getList($project_id);

        // 患者标签
        $patientTags = Yii::$app->services->patientTags->findList([
            'patient_user_id' => $patient_id,
            'status' => Tags::STATUS_ENABLE,
        ]);
        $tagsIds = array_column($patientTags, 'tags_id');

        // 处理是否选中
        foreach ($taglist['list'] as $key => $value) {
            if (isset($value['tags_list']) && $value['tags_list']) {
                foreach ($value['tags_list'] as $k => $v) {
                    if (in_array($v['id'], $tagsIds)) {
                        $value['tags_list'][$k]['checked'] = 1;
                    } else {
                        $value['tags_list'][$k]['checked'] = 2;
                    }
                }
                $taglist['list'][$key]['tags_list'] = $value['tags_list'];
            }
        }
        return $taglist;
    }

    /**
     * 编辑患者标签
     *
     * @return array|mixed
     * @throws HttpException
     * @author chenyuebin
     */
    public function actionPatientTagsEdit()
    {
        $params = Yii::$app->request->post();
        if (!isset($params['tags'])) {
            throw new HttpException(422, '非法操作');
        }
        if (!isset($params['patient_id']) || !$params['patient_id']) {
            throw new HttpException(422, '缺少患者信息');
        }
        // 修改患者标签
        try {
            $patientTags = Yii::$app->services->patientTags->tagsEdit([
                'patient_user_id' => $params['patient_id'],
                'tags_id' => $params['tags'],
                'project_id' => $this->projectId,
            ]);
            return $patientTags;
        } catch (\Exception $exception) {
            throw new HttpException(422, $exception->getMessage());
        }

        return $params;
    }

    /**
     * @api {get} /v1/patient/index/add-list 新增患者列表
     * @apiName add-list
     * @apiGroup Index
     *
     * @apiParam {String} start_time                                       开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                         结束时间【格式：2020-01-01】
     * @apiParam {String} keywords                                         关键词【姓名or手机号】
     * @apiParam {Number} outpatient_type_id                               就诊类型
     * @apiParam {String} tags_ids                                         标签IDs【多个用','分割】
     * @apiParam {Number} fault_diagnosis_type                             断诊次数类型【1一次、2两次、3三次、4四次以上】
     * @apiParam {Number} sort_last_revisiting_type                        上次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_revisiting_type                        下次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_last_callback_type                          上次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_callback_type                          下次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_revisiting_type                             复诊次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_callback_type                               回访次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_missed_type                                 未到诊天数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页显示数量
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     患者列表
     * @apiSuccess {Number}  data.list.id                                  患者ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {String}  data.list.name                                患者姓名
     * @apiSuccess {Number}  data.list.age                                 患者年龄
     * @apiSuccess {Number}  data.list.gender                              患者性别
     * @apiSuccess {String}  data.list.gender_str                          患者性别值
     * @apiSuccess {String}  data.list.patient_card_id                     诊疗号
     * @apiSuccess {String}  data.list.clinic_name                         诊室名称
     * @apiSuccess {String}  data.list.mobile                              手机号
     * @apiSuccess {String}  data.list.last_revisiting_time_str            上次到诊时间
     * @apiSuccess {String}  data.list.next_revisiting_time_str            下次到诊时间
     * @apiSuccess {String}  data.list.last_callback_time_str              上次回访时间
     * @apiSuccess {String}  data.list.next_callback_time_str              下次回访时间
     * @apiSuccess {Number}  data.list.outpatient_type_id                  就诊类型ID
     * @apiSuccess {String}  data.list.outpatient_name                     就诊类型值
     * @apiSuccess {Array}   data.list.patient_tags_name_arr               患者标签数组
     * @apiSuccess {Number}  data.list.revisiting_count                    复诊次数
     * @apiSuccess {Number}  data.list.callback_count                      回访次数
     * @apiSuccess {Number}  data.list.missed_count                        未到诊天数
     * @apiSuccess {String}  data.list.city_name                           地区
     * @apiSuccess {Number}  data.list.source_channel_id                   来源ID
     * @apiSuccess {String}  data.list.source_name                         来源值
     * @apiSuccess {String}  data.list.remark                              备注
     * @apiSuccess {Number}  data.list.fault_diagnosis_count               断诊次数
     * @apiSuccess {String}  data.list.diseases_name                       病种
     * @apiSuccess {Array}   data.condition                                筛选条件
     * @apiSuccess {Array}   data.condition.outpatient_type_list           就诊类型
     * @apiSuccess {Number}  data.condition.outpatient_type_list.id        ID
     * @apiSuccess {String}  data.condition.outpatient_type_list.name      名称
     * @apiSuccess {Array}   data.condition.tags_list                      标签【同上】
     */
    public function actionAddList()
    {
        $params = Yii::$app->request->get();
        $params['member_id'] = Yii::$app->user->identity->member_id;
        $params['project_id'] = $this->projectId;

        $attr = Yii::$app->services->attr->findInfo([
            'member_id' => Yii::$app->user->identity->member_id,
            'project_id' => $this->projectId,
        ]);
        $type = 1;
        // 是否返回客服就诊类型
        if ($attr && $attr->profession_id == Profession::ID_CUSTOMER) { // 客服
            $type = 1;
            $params['belong_member_id'] = $params['member_id'];
        } else {// 医助
            $type = 2;
            $params['belong_assistant_id'] = $params['member_id'];
        }


        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientUser->getAddListPage($params, (int)$page, (int)$pageSize);

        // 格式化列表数据
        $data['list'] = Yii::$app->services->patientUser->getListPageFormat($data['list'], $type);

        // 获取筛选条件
        $data['condition'] = [
            'tags_list' => CommonService::getTagsList(),
            'outpatient_type_list' => CommonService::getOutpatientTypeList(0),
        ];

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/arrive-list 已到患者列表
     * @apiName arrive-list
     * @apiGroup Index
     *
     * @apiParam {String} start_time                                       开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                         结束时间【格式：2020-01-01】
     * @apiParam {String} keywords                                         关键词【姓名or手机号】
     * @apiParam {Number} outpatient_type_id                               就诊类型
     * @apiParam {String} tags_ids                                         标签IDs【多个用','分割】
     * @apiParam {Number} clinic_id                                        门诊ID
     * @apiParam {Number} edit_type                                        类型【0默认（我的报表）、1客服、2医助】
     * @apiParam {Number} belong_member_id                                 客服归属人ID
     * @apiParam {Number} belong_assistant_id                              医助归属人ID
     * @apiParam {Number} fault_diagnosis_type                             断诊次数类型【1一次、2两次、3三次、4四次以上】
     * @apiParam {Number} sort_last_revisiting_type                        上次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_revisiting_type                        下次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_last_callback_type                          上次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_callback_type                          下次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_revisiting_type                             复诊次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_callback_type                               回访次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_missed_type                                 未到诊天数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页显示数量
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     患者列表
     * @apiSuccess {Number}  data.list.id                                  患者ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {String}  data.list.name                                患者姓名
     * @apiSuccess {Number}  data.list.age                                 患者年龄
     * @apiSuccess {Number}  data.list.gender                              患者性别
     * @apiSuccess {String}  data.list.gender_str                          患者性别值
     * @apiSuccess {String}  data.list.patient_card_id                     诊疗号
     * @apiSuccess {String}  data.list.clinic_name                         诊室名称
     * @apiSuccess {String}  data.list.mobile                              手机号
     * @apiSuccess {String}  data.list.last_revisiting_time_str            上次到诊时间
     * @apiSuccess {String}  data.list.next_revisiting_time_str            下次到诊时间
     * @apiSuccess {String}  data.list.last_callback_time_str              上次回访时间
     * @apiSuccess {String}  data.list.next_callback_time_str              下次回访时间
     * @apiSuccess {Number}  data.list.outpatient_type_id                  就诊类型ID
     * @apiSuccess {String}  data.list.outpatient_name                     就诊类型值
     * @apiSuccess {Array}   data.list.patient_tags_name_arr               患者标签数组
     * @apiSuccess {Number}  data.list.revisiting_count                    复诊次数
     * @apiSuccess {Number}  data.list.callback_count                      回访次数
     * @apiSuccess {Number}  data.list.missed_count                        未到诊天数
     * @apiSuccess {String}  data.list.city_name                           地区
     * @apiSuccess {Number}  data.list.source_channel_id                   来源ID
     * @apiSuccess {String}  data.list.source_name                         来源值
     * @apiSuccess {String}  data.list.remark                              备注
     * @apiSuccess {Number}  data.list.fault_diagnosis_count               断诊次数
     * @apiSuccess {String}  data.list.diseases_name                       病种
     * @apiSuccess {Array}   data.condition                                筛选条件
     * @apiSuccess {Array}   data.condition.outpatient_type_list           就诊类型
     * @apiSuccess {Number}  data.condition.outpatient_type_list.id        ID
     * @apiSuccess {String}  data.condition.outpatient_type_list.name      名称
     * @apiSuccess {Array}   data.condition.tags_list                      标签【同上】
     * @apiSuccess {Array}   data.condition.member_customer_list           客服归属人【同上】
     * @apiSuccess {Array}   data.condition.member_medical_list            医助归属人【同上】
     * @apiSuccess {Array}   data.tab_totals                               tab统计数量
     * @apiSuccess {Number}  data.tab_totals.all_num                       全部
     * @apiSuccess {Number}  data.tab_totals.arrive_num                    已到
     * @apiSuccess {Number}  data.tab_totals.order_arrive_num              预到
     * @apiSuccess {Number}  data.tab_totals.unarrive_num                  未到
     */
    public function actionArriveList()
    {
        $params = Yii::$app->request->get();

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientUser->getArriveListPage($params, (int)$page, (int)$pageSize);

        // 格式化列表数据
        $data['list'] = Yii::$app->services->patientUser->getListPageFormat($data['list'], $data['type']);
        unset($data['type']);

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/order-arrive-list 预到患者列表
     * @apiName order-arrive-list
     * @apiGroup Index
     *
     * @apiParam {String} start_time                                       开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                         结束时间【格式：2020-01-01】
     * @apiParam {String} keywords                                         关键词【姓名or手机号】
     * @apiParam {Number} outpatient_type_id                               就诊类型
     * @apiParam {String} tags_ids                                         标签IDs【多个用','分割】
     * @apiParam {Number} clinic_id                                        门诊ID
     * @apiParam {Number} edit_type                                        类型【0默认（我的报表）、1客服、2医助】
     * @apiParam {Number} belong_member_id                                 客服归属人ID
     * @apiParam {Number} belong_assistant_id                              医助归属人ID
     * @apiParam {Number} fault_diagnosis_type                             断诊次数类型【1一次、2两次、3三次、4四次以上】
     * @apiParam {Number} sort_last_revisiting_type                        上次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_revisiting_type                        下次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_last_callback_type                          上次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_callback_type                          下次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_revisiting_type                             复诊次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_callback_type                               回访次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_missed_type                                 未到诊天数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页显示数量
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     患者列表
     * @apiSuccess {Number}  data.list.id                                  患者ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {String}  data.list.name                                患者姓名
     * @apiSuccess {Number}  data.list.age                                 患者年龄
     * @apiSuccess {Number}  data.list.gender                              患者性别
     * @apiSuccess {String}  data.list.gender_str                          患者性别值
     * @apiSuccess {String}  data.list.patient_card_id                     诊疗号
     * @apiSuccess {String}  data.list.clinic_name                         诊室名称
     * @apiSuccess {String}  data.list.mobile                              手机号
     * @apiSuccess {String}  data.list.last_revisiting_time_str            上次到诊时间
     * @apiSuccess {String}  data.list.next_revisiting_time_str            下次到诊时间
     * @apiSuccess {String}  data.list.last_callback_time_str              上次回访时间
     * @apiSuccess {String}  data.list.next_callback_time_str              下次回访时间
     * @apiSuccess {Number}  data.list.outpatient_type_id                  就诊类型ID
     * @apiSuccess {String}  data.list.outpatient_name                     就诊类型值
     * @apiSuccess {Array}   data.list.patient_tags_name_arr               患者标签数组
     * @apiSuccess {Number}  data.list.revisiting_count                    复诊次数
     * @apiSuccess {Number}  data.list.callback_count                      回访次数
     * @apiSuccess {Number}  data.list.missed_count                        未到诊天数
     * @apiSuccess {String}  data.list.city_name                           地区
     * @apiSuccess {Number}  data.list.source_channel_id                   来源ID
     * @apiSuccess {String}  data.list.source_name                         来源值
     * @apiSuccess {String}  data.list.remark                              备注
     * @apiSuccess {Number}  data.list.fault_diagnosis_count               断诊次数
     * @apiSuccess {String}  data.list.diseases_name                       病种
     * @apiSuccess {Array}   data.condition                                筛选条件
     * @apiSuccess {Array}   data.condition.outpatient_type_list           就诊类型
     * @apiSuccess {Number}  data.condition.outpatient_type_list.id        ID
     * @apiSuccess {String}  data.condition.outpatient_type_list.name      名称
     * @apiSuccess {Array}   data.condition.tags_list                      标签【同上】
     * @apiSuccess {Array}   data.condition.member_customer_list           客服归属人【同上】
     * @apiSuccess {Array}   data.condition.member_medical_list            医助归属人【同上】
     * @apiSuccess {Array}   data.tab_totals                               tab统计数量
     * @apiSuccess {Number}  data.tab_totals.all_num                       全部
     * @apiSuccess {Number}  data.tab_totals.arrive_num                    已到
     * @apiSuccess {Number}  data.tab_totals.order_arrive_num              预到
     * @apiSuccess {Number}  data.tab_totals.unarrive_num                  未到
     */
    public function actionOrderArriveList()
    {
        $params = Yii::$app->request->get();

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientUser->getOrderArriveListPage($params, (int)$page, (int)$pageSize);

        // 格式化列表数据
        $data['list'] = Yii::$app->services->patientUser->getListPageFormat($data['list'], $data['type']);
        unset($data['type']);

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/unarrive-list 过期未到患者列表
     * @apiName unarrive-list
     * @apiGroup Index
     *
     * @apiParam {String} start_time                                       开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                         结束时间【格式：2020-01-01】
     * @apiParam {String} keywords                                         关键词【姓名or手机号】
     * @apiParam {Number} outpatient_type_id                               就诊类型
     * @apiParam {String} tags_ids                                         标签IDs【多个用','分割】
     * @apiParam {Number} clinic_id                                        门诊ID
     * @apiParam {Number} edit_type                                        类型【0默认（我的报表）、1客服、2医助】
     * @apiParam {Number} belong_member_id                                 客服归属人ID
     * @apiParam {Number} belong_assistant_id                              医助归属人ID
     * @apiParam {Number} fault_diagnosis_type                             断诊次数类型【1一次、2两次、3三次、4四次以上】
     * @apiParam {Number} sort_last_revisiting_type                        上次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_revisiting_type                        下次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_last_callback_type                          上次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_callback_type                          下次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_revisiting_type                             复诊次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_callback_type                               回访次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_missed_type                                 未到诊天数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页显示数量
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     患者列表
     * @apiSuccess {Number}  data.list.id                                  患者ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {String}  data.list.name                                患者姓名
     * @apiSuccess {Number}  data.list.age                                 患者年龄
     * @apiSuccess {Number}  data.list.gender                              患者性别
     * @apiSuccess {String}  data.list.gender_str                          患者性别值
     * @apiSuccess {String}  data.list.patient_card_id                     诊疗号
     * @apiSuccess {String}  data.list.clinic_name                         诊室名称
     * @apiSuccess {String}  data.list.mobile                              手机号
     * @apiSuccess {String}  data.list.last_revisiting_time_str            上次到诊时间
     * @apiSuccess {String}  data.list.next_revisiting_time_str            下次到诊时间
     * @apiSuccess {String}  data.list.last_callback_time_str              上次回访时间
     * @apiSuccess {String}  data.list.next_callback_time_str              下次回访时间
     * @apiSuccess {Number}  data.list.outpatient_type_id                  就诊类型ID
     * @apiSuccess {String}  data.list.outpatient_name                     就诊类型值
     * @apiSuccess {Array}   data.list.patient_tags_name_arr               患者标签数组
     * @apiSuccess {Number}  data.list.revisiting_count                    复诊次数
     * @apiSuccess {Number}  data.list.callback_count                      回访次数
     * @apiSuccess {Number}  data.list.missed_count                        未到诊天数
     * @apiSuccess {String}  data.list.city_name                           地区
     * @apiSuccess {Number}  data.list.source_channel_id                   来源ID
     * @apiSuccess {String}  data.list.source_name                         来源值
     * @apiSuccess {String}  data.list.remark                              备注
     * @apiSuccess {Number}  data.list.fault_diagnosis_count               断诊次数
     * @apiSuccess {String}  data.list.diseases_name                       病种
     * @apiSuccess {Array}   data.condition                                筛选条件
     * @apiSuccess {Array}   data.condition.outpatient_type_list           就诊类型
     * @apiSuccess {Number}  data.condition.outpatient_type_list.id        ID
     * @apiSuccess {String}  data.condition.outpatient_type_list.name      名称
     * @apiSuccess {Array}   data.condition.tags_list                      标签【同上】
     * @apiSuccess {Array}   data.condition.member_customer_list           客服归属人【同上】
     * @apiSuccess {Array}   data.condition.member_medical_list            医助归属人【同上】
     * @apiSuccess {Array}   data.tab_totals                               tab统计数量
     * @apiSuccess {Number}  data.tab_totals.all_num                       全部
     * @apiSuccess {Number}  data.tab_totals.arrive_num                    已到
     * @apiSuccess {Number}  data.tab_totals.order_arrive_num              预到
     * @apiSuccess {Number}  data.tab_totals.unarrive_num                  未到
     */
    public function actionUnarriveList()
    {
        $params = Yii::$app->request->get();

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientUser->getUnarriveListPage($params, (int)$page, (int)$pageSize);

        // 格式化列表数据
        $data['list'] = Yii::$app->services->patientUser->getListPageFormat($data['list'], $data['type']);
        unset($data['type']);

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/tab-total 患者tab总数集合
     * @apiName tab-total
     * @apiGroup Index
     *
     * @apiParam {Number} edit_type                             类型【1客服、2医助】
     *
     * @apiSuccess {Object}  data                               返回数据
     */
    public function actionTabTotal()
    {
        $params = Yii::$app->request->get();
        $params['edit_type'] = $params['edit_type'] ?? 0;

        $userService = new UserService();
        // tab总数
        $data['tab_totals'] = $userService->getTabTotal((int)$params['edit_type']);

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/callbacked-list 已回访患者列表
     * @apiName callbacked-list
     * @apiGroup Index
     *
     * @apiParam {String} start_time                                       开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                         结束时间【格式：2020-01-01】
     * @apiParam {String} keywords                                         关键词【姓名or手机号】
     * @apiParam {Number} outpatient_type_id                               就诊类型
     * @apiParam {String} tags_ids                                         标签IDs【多个用','分割】
     * @apiParam {Number} fault_diagnosis_type                             断诊次数类型【1一次、2两次、3三次、4四次以上】
     * @apiParam {Number} sort_last_revisiting_type                        上次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_revisiting_type                        下次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_last_callback_type                          上次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_callback_type                          下次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_revisiting_type                             复诊次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_callback_type                               回访次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_missed_type                                 未到诊天数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页显示数量
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     患者列表
     * @apiSuccess {Number}  data.list.id                                  患者ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {String}  data.list.name                                患者姓名
     * @apiSuccess {Number}  data.list.age                                 患者年龄
     * @apiSuccess {Number}  data.list.gender                              患者性别
     * @apiSuccess {String}  data.list.gender_str                          患者性别值
     * @apiSuccess {String}  data.list.patient_card_id                     诊疗号
     * @apiSuccess {String}  data.list.clinic_name                         诊室名称
     * @apiSuccess {String}  data.list.mobile                              手机号
     * @apiSuccess {String}  data.list.last_revisiting_time_str            上次到诊时间
     * @apiSuccess {String}  data.list.next_revisiting_time_str            下次到诊时间
     * @apiSuccess {String}  data.list.last_callback_time_str              上次回访时间
     * @apiSuccess {String}  data.list.next_callback_time_str              下次回访时间
     * @apiSuccess {Number}  data.list.outpatient_type_id                  就诊类型ID
     * @apiSuccess {String}  data.list.outpatient_name                     就诊类型值
     * @apiSuccess {Array}   data.list.patient_tags_name_arr               患者标签数组
     * @apiSuccess {Number}  data.list.revisiting_count                    复诊次数
     * @apiSuccess {Number}  data.list.callback_count                      回访次数
     * @apiSuccess {Number}  data.list.missed_count                        未到诊天数
     * @apiSuccess {String}  data.list.city_name                           地区
     * @apiSuccess {Number}  data.list.source_channel_id                   来源ID
     * @apiSuccess {String}  data.list.source_name                         来源值
     * @apiSuccess {String}  data.list.remark                              备注
     * @apiSuccess {Number}  data.list.fault_diagnosis_count               断诊次数
     * @apiSuccess {String}  data.list.diseases_name                       病种
     * @apiSuccess {Array}   data.condition                                筛选条件
     * @apiSuccess {Array}   data.condition.outpatient_type_list           就诊类型
     * @apiSuccess {Number}  data.condition.outpatient_type_list.id        ID
     * @apiSuccess {String}  data.condition.outpatient_type_list.name      名称
     * @apiSuccess {Array}   data.condition.tags_list                      标签【同上】
     */
    public function actionCallbackedList()
    {
        $params = Yii::$app->request->get();
        $params['member_id'] = Yii::$app->user->identity->member_id;
        $params['project_id'] = $this->projectId;

        $attr = Yii::$app->services->attr->findInfo([
            'member_id' => Yii::$app->user->identity->member_id,
            'project_id' => $this->projectId,
        ]);
        $type = 1;
        // 是否返回客服就诊类型
        if ($attr && $attr->profession_id == Profession::ID_CUSTOMER) { // 客服
            $type = 1;
            $params['belong_member_id'] = $params['member_id'];
        } else {// 医助
            $type = 2;
            $params['belong_assistant_id'] = $params['member_id'];
        }

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientUser->getCallbackListPage($params, (int)$page, (int)$pageSize);

        // 格式化列表数据
        $data['list'] = Yii::$app->services->patientUser->getListPageFormat($data['list'], $type);

        // 获取筛选条件
        $params = [
            'get_risk_type' => 1,
            'get_effect_type' => 1,
        ];
        $data['condition'] = Yii::$app->services->patientUser->getConditionList($params, $this->projectId);
        $data['condition']['outpatient_type_list'] = CommonService::getOutpatientTypeList(0);
        $condition['tags_list'] = CommonService::getTagsList();

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/uncallback-list 过期未回访患者列表
     * @apiName uncallback-list
     * @apiGroup Index
     *
     * @apiParam {String} start_time                                       开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                         结束时间【格式：2020-01-01】
     * @apiParam {String} keywords                                         关键词【姓名or手机号】
     * @apiParam {Number} outpatient_type_id                               就诊类型
     * @apiParam {String} tags_ids                                         标签IDs【多个用','分割】
     * @apiParam {Number} fault_diagnosis_type                             断诊次数类型【1一次、2两次、3三次、4四次以上】
     * @apiParam {Number} sort_last_revisiting_type                        上次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_revisiting_type                        下次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_last_callback_type                          上次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_next_callback_type                          下次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_revisiting_type                             复诊次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_callback_type                               回访次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_missed_type                                 未到诊天数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize                                         每页显示数量
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Number}  data.page                                     当前页码
     * @apiSuccess {Number}  data.pageSize                                 每页显示数
     * @apiSuccess {Number}  data.total                                    总数
     * @apiSuccess {Array}   data.list                                     患者列表
     * @apiSuccess {Number}  data.list.id                                  患者ID
     * @apiSuccess {Number}  data.list.project_id                          项目ID
     * @apiSuccess {String}  data.list.name                                患者姓名
     * @apiSuccess {Number}  data.list.age                                 患者年龄
     * @apiSuccess {Number}  data.list.gender                              患者性别
     * @apiSuccess {String}  data.list.gender_str                          患者性别值
     * @apiSuccess {String}  data.list.patient_card_id                     诊疗号
     * @apiSuccess {String}  data.list.clinic_name                         诊室名称
     * @apiSuccess {String}  data.list.mobile                              手机号
     * @apiSuccess {String}  data.list.last_revisiting_time_str            上次到诊时间
     * @apiSuccess {String}  data.list.next_revisiting_time_str            下次到诊时间
     * @apiSuccess {String}  data.list.last_callback_time_str              上次回访时间
     * @apiSuccess {String}  data.list.next_callback_time_str              下次回访时间
     * @apiSuccess {Number}  data.list.outpatient_type_id                  就诊类型ID
     * @apiSuccess {String}  data.list.outpatient_name                     就诊类型值
     * @apiSuccess {Array}   data.list.patient_tags_name_arr               患者标签数组
     * @apiSuccess {Number}  data.list.revisiting_count                    复诊次数
     * @apiSuccess {Number}  data.list.callback_count                      回访次数
     * @apiSuccess {Number}  data.list.missed_count                        未到诊天数
     * @apiSuccess {String}  data.list.city_name                           地区
     * @apiSuccess {Number}  data.list.source_channel_id                   来源ID
     * @apiSuccess {String}  data.list.source_name                         来源值
     * @apiSuccess {String}  data.list.remark                              备注
     * @apiSuccess {Number}  data.list.fault_diagnosis_count               断诊次数
     * @apiSuccess {String}  data.list.diseases_name                       病种
     * @apiSuccess {Array}   data.condition                                筛选条件
     * @apiSuccess {Array}   data.condition.outpatient_type_list           就诊类型
     * @apiSuccess {Number}  data.condition.outpatient_type_list.id        ID
     * @apiSuccess {String}  data.condition.outpatient_type_list.name      名称
     * @apiSuccess {Array}   data.condition.tags_list                      标签【同上】
     */
    public function actionUncallbackList()
    {
        $params = Yii::$app->request->get();
        $params['member_id'] = Yii::$app->user->identity->member_id;
        $params['project_id'] = $this->projectId;

        $attr = Yii::$app->services->attr->findInfo([
            'member_id' => Yii::$app->user->identity->member_id,
            'project_id' => $this->projectId,
        ]);
        $type = 1;
        // 是否返回客服就诊类型
        if ($attr && $attr->profession_id == Profession::ID_CUSTOMER) { // 客服
            $type = 1;
            $params['belong_member_id'] = $params['member_id'];
        } else {// 医助
            $type = 2;
            $params['belong_assistant_id'] = $params['member_id'];
        }

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientUser->getUncallbackListPage($params, (int)$page, (int)$pageSize);

        // 格式化列表数据
        $data['list'] = Yii::$app->services->patientUser->getListPageFormat($data['list'], $type);

        // 获取筛选条件
        $data['condition'] =[
            'tags_list' => CommonService::getTagsList(),
            'outpatient_type_list' => CommonService::getOutpatientTypeList(0),
        ];

        return $data;
    }

    /**
     * @api {get} /v1/patient/index/batch-condition-list 获取分配患者筛选条件列表
     * @apiName batch-condition-list
     * @apiGroup Index
     *
     *
     * @apiSuccess {Object}  data                                          返回数据
     * @apiSuccess {Array}   data.condition                                筛选条件
     * @apiSuccess {Array}   data.condition.member_customer_list           客服归属人
     * @apiSuccess {Number}  data.condition.source_channel_list.id         ID
     * @apiSuccess {String}  data.condition.source_channel_list.name       名称
     * @apiSuccess {Array}   data.condition.member_medical_list            医助归属人【同上】
     */
    public function actionBatchConditionList()
    {
        $data = [];

        // 获取筛选条件
        $params = [
            'get_customer_member' => 1,
            'get_medical_member' => 1,
        ];
        $isCheckType = Yii::$app->user->identity->member->is_super == Member::IS_SUPER_NO ? 1 : 0;
        $condition = Yii::$app->services->patientUser->getConditionList($params, $this->projectId, $isCheckType);

        $data['condition'] = $condition;

        return $data;
    }


    /**
     * @api {post} /v1/patient/index/update-next-revisiting-time 更新患者下次复诊时间
     * @apiName update-next-revisiting-time
     * @apiGroup Index
     *
     * @apiDescription 更新患者下次复诊时间
     *
     * @apiParam {Number}   id                      患者ID
     * @apiParam {Date}     next_revisiting_time    下次复诊时间
     *
     * @apiSuccess {Number} code    状态码，0：请求成功
     * @apiSuccess {String} message   提示信息
     * @apiSuccess {Object} data    返回数据
     *
     */
    public function actionUpdateNextRevisitingTime()
    {
        $params = Yii::$app->request->post();
        if (!isset($params['id'])) {
            throw new HttpException(422, '缺少患者信息');
        }
        if (!isset($params['next_revisiting_time']) || !$params['next_revisiting_time']) {
            throw new HttpException(422, '参数错误');
        }
        $nextRevisitingTime = strtotime($params['next_revisiting_time']);//1589269267

        // 修改患者标签
        try {
            $nextRevisitingRe = Yii::$app->services->patientUser->updateNextRevisitingTime($params['id'], $nextRevisitingTime);

            return $nextRevisitingRe;
        } catch (\Exception $exception) {
            throw new HttpException(422, $exception->getMessage());
        }
    }

    /**
     * @api {GET} /v1/patient/index/doctor-guide-info
     * @apiName 导医详情,返回true,可以点击
     * @apiGroup
     * @author loujie
     */
    public function actionDoctorGuideInfo()
    {
        return true;
    }

    /**
     * 导医登记患者
     *
     * @return int
     * @throws HttpException
     * @author chenyuebin
     */
    public function actionPatientAdd()
    {
        $params = Yii::$app->request->post();
        $params['project_id'] = $this->projectId;

        if (!isset($params['user_name']) || !$params['user_name']) {
            throw new HttpException(422, '请填写患者姓名');
        }

        if (!isset($params['gender']) || !$params['gender']) {
            throw new HttpException(422, '请选择患者性别');
        }

        if (!isset($params['clinic_id']) || !$params['clinic_id']) {
            throw new HttpException(422, '请选择诊室');
        }

        if (!isset($params['patient_card_id']) || !$params['patient_card_id']) {
            throw new HttpException(422, '请填写诊疗号');
        }

        if (Yii::$app->services->patientUser->patientCardCheck($params['project_id'], $params['patient_card_id'])) {
            throw new HttpException(422, '该诊疗号已存在！');
        }

        return Yii::$app->services->patientUser->patientAdd($params);
    }

    /**
     * @api {get} /v1/patient/index/wechat-info 微信信息
     * @apiName wechat-info
     * @apiGroup Index
     *
     * @apiParam {Number} patient_user_id                           患者ID
     *
     * @apiSuccess {Object}  data                                   返回数据
     * @apiSuccess {Array}   data.list                              咨询微信列表
     * @apiSuccess {Number}  data.list.id                           ID
     * @apiSuccess {String}  data.list.wechatid                     微信ID
     * @apiSuccess {String}  data.list.wechatno                     微信号
     * @apiSuccess {String}  data.list.wechatnick                   微信昵称
     * @apiSuccess {String}  data.list.avatar                       头像
     * @apiSuccess {Object}  data.list.contact_info                 联系人信息
     * @apiSuccess {Number}  data.list.contact_info.id              ID
     * @apiSuccess {String}  data.list.contact_info.friendid        微信ID
     * @apiSuccess {String}  data.list.contact_info.friend_wechatno 微信号
     * @apiSuccess {String}  data.list.contact_info.nickname        昵称
     * @apiSuccess {String}  data.list.contact_info.avatar          头像
     * @apiSuccess {Array}   data.list.contact_info.tags_arr        标签【数组】
     * @apiSuccess {String}  data.list.contact_info.country         国家
     * @apiSuccess {String}  data.list.contact_info.province        省
     * @apiSuccess {String}  data.list.contact_info.city            市
     * @apiSuccess {String}  data.list.contact_info.source_type_str 来源
     * @apiSuccess {String}  data.list.contact_info.remark_name     备注名
     * @apiSuccess {String}  data.list.contact_info.state_str       状态值
     * @apiSuccess {Number}  data.list.contact_info.create_day      加好友天数
     * @apiSuccess {Number}  data.list.contact_info.unchat_day      未互动天数
     * @apiSuccess {String}  data.list.contact_info.create_time     添加时间
     */
    public function actionWechatInfo()
    {
        $params = Yii::$app->request->get();
        $id = $params['patient_user_id'] ?? 0;

        $userService = new WechatService();
        return $userService->wechatInfo((int)$id);
    }

    public function actionUnbindWechat()
    {
        $params = Yii::$app->request->post();
        $id = $params['id'] ?? 0;
        $wechat_id = $params['wechat_id'] ?? "";
        $wechatno = $params['wechatno'] ?? "";
        $friendInfo = [$wechat_id,$wechatno];
        $userService = new WechatService();
        return $userService->unbindWechat((int)$id, $friendInfo);
    }

    /**
     * @api {get} /v1/patient/index/wechat-message-list 微信聊天列表
     * @apiName wechat-message-list
     * @apiGroup Index
     *
     * @apiParam {String} wechat_id                                 咨询微信ID
     * @apiParam {String} friend_id                                 好友微信ID
     * @apiParam {Number} page                                      页码【作废】
     * @apiParam {Number} pageSize                                  每页显示数【作废】
     * @apiParam {String} type                                      翻页类型【first首次、prev上次、next下次、end尾次】
     * @apiParam {String} now_date                                  当前日期【格式：2020-01-01，type=prev\next必传】
     * @apiParam {String} patient_user_id                           患者ID【非必填】
     *
     * @apiSuccess {Object}  data                                   返回数据
     */
    public function actionWechatMessageList()
    {
        $params = Yii::$app->request->get();

        $params['date'] = '';
        $params['type'] = $params['type'] ?? '';
        $params['now_date'] = $params['now_date'] ?? date('Y-m-d');
//        $page = $params['page'] ?? 1;
//        $pageSize = $params['pageSize'] ?? 10;
        return CommonHelper::dengta_request('/v1/baiyou/wechat-message-list', array_merge($params, ['page' => 0, 'pageSize' => 0]));
    }

    /**
     * @api {post} /v1/patient/index/sync-patient 同步初诊患者
     * @apiName sync-patient
     * @apiGroup Index
     *
     * @apiParam {String} project_namx_sx       项目缩写
     * @apiParam {String} start_time            开始时间【格式：2020-01-01】
     * @apiParam {String} end_time              结束时间【格式：2020-01-01】
     *
     * @apiSuccess {Object}  data               返回数据
     */
    public function actionSyncPatient()
    {
        $params = Yii::$app->request->post();
        $hospital = $params['project_namx_sx'] ?? '';
        $day = $params['start_time'] ?? date('Y-m-d');
        $endDay = $params['end_time'] ?? '';
        if (empty($day) || empty($endDay)) {
            throw new HttpException(422, '时间段不能为空');
        }
        $project = \common\models\base\Project::findOne([
            'name_sx' => $hospital,
            'status' => \common\models\base\Project::STATUS_ENABLE
        ]);
        if (empty($project)) {
            throw new HttpException(422, '项目不存在');
        }

        ExcelService::registration($hospital, $day, $endDay);
        $params = [
            'hospital' => $hospital,
            'function' => 'actionSyncPatient',
            'day' => date('Y-m-d H:i:s'),
            'status' => 1,
        ];
        ExcelService::errorLog($params);
        return  $hospital .'-'. date('Y-m-d H:i:s').'-success';
    }

    /**
     * @api {get} /v1/patient/index/sync-project-list 获取同步初诊患者项目列表
     * @apiName sync-patient
     * @apiGroup Index
     *
     * @apiParam {String} project_namx_sx       项目缩写
     * @apiParam {String} start_time            开始时间【格式：2020-01-01】
     * @apiParam {String} end_time              结束时间【格式：2020-01-01】
     *
     * @apiSuccess {Object}  data               返回数据
     */
    public function actionSyncProjectList()
    {
        $params = Yii::$app->request->get();
        $service = new ProjectService();
        return $service->getProjectList();
    }

    /**
     * 批量分配南昌数据【按诊室和平均分配给每个医助】
     * @return null
     */
    public function actionUpdateMemberBatch()
    {
        $service = new UserUpdateService();
        return $service->updateMemberBatch();
    }
}
